问题
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