我正在使用python在word中打开一个word文档,并试图在StackOverflow上使用StackOverflow应答来转换它。
我的python代码:
import win32com.client
word = win32com.client.Dispatch('Word.Application')
wdFormatPDF = 17
doc = word.Documents.Open(path)
doc.SaveAs(file_name, FileFormat=wdFormatPDF)
doc.Close()
word.Quit()
但是,在这样做时,我遇到了以下错误:
doc.SaveAs(file_name, FileFormat=wdFormatPDF)
File "<COMObject Open>", line 5, in SaveAs
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Word', 'Command failed', 'wdmain11.chm', 36966, -2146824090), None)
请解释一下这个错误意味着什么,以及如何修复我的代码。
发布于 2022-07-04 12:24:25
我也犯了同样的错误。在我的例子中,我在保存到的目录中没有写权限。
另见:Error pywintypes.com_error occur when convert files docx to files pdf
https://stackoverflow.com/questions/64539049
复制相似问题