Reading Custom Document properties in MS Word File using python

纵然是瞬间 提交于 2019-12-10 09:30:21

问题


How can I get the document properties of a MS-Word 2010 Document using python?

with document properties i mean those who can be added or modified under FILE -> Info-> Properties-> Advanced properties (In MS-WORD 2010)

I'm using python 2.7 on windows764bit and the corresponding pywin32com version to access the doc-file...

I found the CustomProperty-object with the methods value and name witch seem to be the right thing for my purpose (http://msdn.microsoft.com/en-us/library/bb257518%28v=office.12%29.aspx)

But I dont know how to implement the class members in python...

the thing i want to do is to get manually specified properties like author, version...


回答1:


I solved it by myself...

A way to read the custom document properties is:

import win32com.client as win32
word = win32.Dispatch("Word.Application")
word.Visible = 0
doc = word.Documents.Open(file)
try:
    csp= doc.CustomDocumentProperties('property_you_want_to_know').value
    print('property is %s' % csp)

except exception as e:
    print ('\n\n', e)

doc.Saved= False
doc.Save()
doc.Close()

word.Quit()


来源:https://stackoverflow.com/questions/15494754/reading-custom-document-properties-in-ms-word-file-using-python

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