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

淺唱寂寞╮ 提交于 2019-12-02 04:15:16

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

Unfortunately I'm not programmer but have some knowledge of MS-Word VBA and objects hierarchy. This would be to much text to put in comment (where I'd rather put this tip).

If you search your table you have to analyse different Document.StoryRanges to find your table. There are Footers and Headers but they are additionally divided into different types. So, to find you Table 0 you could use something of this structure:

This is VBA code!! I hope you could adjust to your needs. And do it separately for you footers.

doc.StoryRanges(wdEvenPagesHeaderStory).Tables.Count
doc.StoryRanges(wdFirstPageHeaderStory).Tables.Count
doc.StoryRanges(wdPrimaryHeaderStory).Tables.Count
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!