Number of pages of a word document with Python

自作多情 提交于 2019-11-29 12:08:22

You can read the value

<Properties>
<Pages>CountValue</Pages>

from docProps/app.xml in the docx package or

<office:document-meta>
    <office:meta>
        <meta:document-statistic meta:page-count="CountValue">

form meta.xml in odt package.

If these values ​​do not exist (they are optional), you have to make a calculation of the entire document, in fact perform rendering, that much more difficult

Only for those who search for this blog entry....

from win32com.client import Dispatch
#open Word
word = Dispatch('Word.Application')
word.Visible = False
word = word.Documents.Open(doc_path)

#get number of sheets
word.Repaginate()
num_of_sheets = word.ComputeStatistics(2)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!