win32 python拒绝字访问

2024-05-31 23:35:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用python3.6和django1.11。 我用MailMerge创建了一个Word文档,没问题。 现在我需要将此文档保存为pdf文档。在

import win32com.client as win32
from os import path
word = win32.DispatchEx("Word.Application")
filedoc='c:\\growthtech\\Capturar6.docx'
filepdf='c:\\growthtech\\Capturar6.pdf'
in_file = path.abspath(filedoc)
out_file = path.abspath(filepdf)
doc = word.Documents.Open(in_file, 'rb')
doc.SaveAs(new_file, FileFormat=17)
doc.Close()
word.Quit()

在“doc=word.Documents.Open打开(在_文件中,'rb')”。在

^{pr2}$

谢谢你的帮助。在


Tags: pathin文档importdocpdfwordfile
1条回答
网友
1楼 · 发布于 2024-05-31 23:35:41

这应该是有效的:

import win32com.client as win32
from os import path
word = win32.DispatchEx("Word.Application")
in_file = path.abspath('c:\\growthtech\\Capturar6.docx')
out_file = path.abspath('c:\\growthtech\\Capturar6.pdf')
# just one argument here
doc = word.Documents.Open(in_file)
# was: 'new_file'
doc.SaveAs(out_file, FileFormat=17)
doc.Close()
word.Quit()

相关问题 更多 >