我試圖使用Python與win32組件自動化Microsoft Office Word 2010文檔。在那邊我需要閱讀並獲取WORD文檔的標題信息。我看了一下MSDN庫(並認爲getFieldNames可以幫助我),甚至看看@Editing MS Word header with win32com(使用這個我只能編輯標題信息),但沒有一個適用於我。Python:Win32:獲取Word文檔中的標題信息
我的代碼片段是:
..//
#tell word to open the document
word.Documents.Open (IP_Directory_Dest + "\\" + name)
#open it internally
doc = word.Documents(1)
### get the header of file - using this gives me Attribute Error
## header = doc.getFieldNames()
## print ('Header = ', header)
..//
而且當我使用getFieldNames(),它提供了一個錯誤「AttributeError的:' '對象沒有屬性'getFieldNames'「,這使我相信在對象lib中沒有像getFieldNames這樣的屬性。
對此的任何建議是最受歡迎的。
對這個有什麼想法? – Varun