Reading Table Contet In Header And Footer In MS-Word File Using Python

前端 未结 2 471
情歌与酒
情歌与酒 2021-01-22 03:49

This is my extended question for the question:

How to read contents of an Table in MS-Word file Using Python?

The solution provided by @YusuMishi is great, but

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-22 04:08

    Accessing Headers and Footers is a bit tricky. Here is how to do it:

    HeaderTable = doc.Sections(1).Headers(1).Range.Tables(1)
    FooterTable = doc.Sections(1).Footers(1).Range.Tables(1)
    

    You can get the table count this way:

    HeaderTablesCount = doc.Sections(1).Headers(1).Range.Tables.Count
    FooterTablesCount = doc.Sections(1).Footers(1).Range.Tables.Count
    

    And get the text from cells this way:

    HeaderTable.Cell(1,1).Range.Text
    FooterTable.Cell(1,1).Range.Text
    

提交回复
热议问题