我正在使用Word 2013自动创建一个报告作为docx,然后将其保存为pdf格式.
但是当我调用函数SaveAs2()时,脚本会弹出"另存为"窗口并抛出此异常:
(-2147352567, 'Exception occurred.', (0, u'Microsoft Word', u'Command failed', u'wdmain11.chm', 36966, -2146824090), None)
Run Code Online (Sandbox Code Playgroud)
这是我打开并保存为新文件的代码:
self.path = os.path.abspath(path)
self.wordApp = win32.Dispatch('Word.Application') #create a word application object
self.wordApp.Visible = False # if false hide the word application (app does't open but still usable)
self.document = self.wordApp.Documents.Open(self.path + "/" + documentRef) # opening the template file
absFileName = "D:\\test.pdf"
self.document.SaveAs2(FileName=absFileName,FileFormat=17)
Run Code Online (Sandbox Code Playgroud)
我正在使用:python2.7与pywin32(build 219)
有人知道为什么它不起作用?