Python读取doc文件时候出错
原始代码如下:
import win32com from win32com.client import Dispatch,constants word = win32com.client.Dispatch('word.application') word.displayalerts=0 word.visible=0 countdoc=word.Documents.Count print(countdoc) doc=word.Document.Open(r"D:\python learn\word\hi.doc") doc.SaveAs(u'D:\python learn\word\Hi.docx',4)
报错:
Traceback (most recent call last):
File "D:/python learn/code/findData/getWordInfo.py", line 14, in <module>
doc=word.Document.Open(r"D:\python learn\word\hi.doc")
File "D:\python learn\code\findData\venv\lib\site-packages\win32com\client\dynamic.py", line 527, in __getattr__
raise AttributeError("%s.%s" % (self._username_, attr))
AttributeError: word.application.Document
解决方案:
结果: