Read From PowerPoint Table in Python?

↘锁芯ラ 提交于 2019-12-02 06:19:53

Your code will miss more text than just tables; it won't see text in shapes that are part of groups, for example.

For tables, you'll need to do a couple things:

Test the shape to see if the shape's .HasTable property is true. If so, you can work with the shape's .Table object to extract the text. Conceptually, and very aircode:

For r = 1 to tbl.rows.count
   For c = 1 to tbl.columns.count
      tbl.cell(r,c).Shape.Textframe.Text ' is what you're after

This works for me:

    def access_table(): 
            slide = prs.slides[0] #first slide
            table = slide.shapes[2].table # maybe 0..n
            for r in table.rows:
                    s = ""
                    for c in r.cells:
                            s += c.text_frame.text + " | "
                            #to write
                            #c.text_frame.text = "example"
                    print s
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!