word转pdf遇到问题(提示库没有注册)
代码如下:
#word转pdf
from win32com.client import Dispatch,constants,gencache
docx_path=”洛神赋.docx”
pdf_path=”洛神赋.pdf”
gencache.EnsureModule(‘{00020905-0000-0000-C000-000000000046}’,0,8,4)
wd=Dispatch(“Word.Application”)
doc=wd.Documents.Open(docx_path,ReadOnly=1)
doc.ExportAsFixedFormat(pdf_path,constants.wdExportFormatPDF,Item=constants.wdExportDocumentWithMarkup,CreateBookmarks=constants.wdExportCreateHeadingBookmarks)
wd.Quit(constants.wdDoNotSaveChanges)
#错误:
但是运行之后出现以下错误 不知道怎么解决:
com_error Traceback (most recent call last)
Cell In[2], line 7
4 docx_path=”洛神赋.docx”
5 pdf_path=”洛神赋.pdf”
—-> 7 gencache.EnsureModule(‘{00020905-0000-0000-C000-000000000046}’,0,8,4)
9 wd=Dispatch(“Word.Application”)
11 doc=wd.Documents.Open(docx_path,ReadOnly=1)
File E:\ProgramData\anaconda3\Lib\site-packages\win32com\client\gencache.py:598, in EnsureModule(typelibCLSID, lcid, major, minor, progressInstance, bValidateFile, bForDemand, bBuildHidden)
596 return ret
597 # print “Rebuilding: “, major, minor
–> 598 module = MakeModuleForTypelib(
599 typelibCLSID,
600 lcid,
601 major,
602 minor,
603 progressInstance,
604 bForDemand=bForDemand,
605 bBuildHidden=bBuildHidden,
606 )
607 # If we replaced something, reload it
608 if bReloadNeeded:
File E:\ProgramData\anaconda3\Lib\site-packages\win32com\client\gencache.py:315, in MakeModuleForTypelib(typelibCLSID, lcid, major, minor, progressInstance, bForDemand, bBuildHidden)
298 “””Generate support for a type library.
299
300 Given the IID, LCID and version information for a type library, generate
(…)
311 use the GUI progress bar.
312 “””
313 from . import makepy
–> 315 makepy.GenerateFromTypeLibSpec(
316 (typelibCLSID, lcid, major, minor),
317 progressInstance=progressInstance,
318 bForDemand=bForDemand,
319 bBuildHidden=bBuildHidden,
320 )
321 return GetModuleForTypelib(typelibCLSID, lcid, major, minor)
File E:\ProgramData\anaconda3\Lib\site-packages\win32com\client\makepy.py:257, in GenerateFromTypeLibSpec(typelibInfo, file, verboseLevel, progressInstance, bUnicodeToString, bForDemand, bBuildHidden)
254 if isinstance(typelibInfo, tuple):
255 # Tuple
256 typelibCLSID, lcid, major, minor = typelibInfo
–> 257 tlb = pythoncom.LoadRegTypeLib(typelibCLSID, major, minor, lcid)
258 spec = selecttlb.TypelibSpec(typelibCLSID, lcid, major, minor)
259 spec.FromTypelib(tlb, str(typelibCLSID))
com_error: (-2147319779, ‘库没有注册。’, None, None)
#尝试的解决方法:
下载MDI Jade 6
然而没有成功 不知道还有什么解决方法
推荐文章: