import os
import sys
from docx2pdf import convert
convert("D:\Dev2Ease\PyC\Output Word","D:\Dev2Ease\PyC\Output Pdf")
print ("All the files have been converted to pdf")对于上面提到的代码,当执行在progress...however中时,我得到一个错误--从docx到pdf的转换正在发生。只是我一直在犯错误。有人能帮我吗?
Traceback (most recent call last):
File "D:/Dev2Ease/PyC/word2pdf.py", line 5, in <module>
convert("D:\Dev2Ease\PyC\Output Word","D:\Dev2Ease\PyC\Output Pdf")
File "C:\Users\Shailesh\AppData\Roaming\Python\Python310\site-packages\docx2pdf\__init__.py", line 106, in convert
return windows(paths, keep_active)
File "C:\Users\Shailesh\AppData\Roaming\Python\Python310\site-packages\docx2pdf\__init__.py", line 25, in windows
doc = word.Documents.Open(str(docx_filepath))
File "<COMObject <unknown>>", line 5, in Open
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Word', 'The file appears to be corrupted.', 'wdmain11.chm', 25272, -2146822496), None)发布于 2022-06-20 15:12:33
当试图写入不存在的文件:pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147352565), None)时,这似乎是一种趋势。
为了获得更一致的路径变量,我建议使用os包。这样你就能更肯定自己的路了。然后将您的路径设置为:
import os
from docx2pdf import convert
path1 = os.path.join("D:/", "Dev2Ease", "PyC", "Output", "Word")
path2 = os.path.join("D:/", "Dev2Ease", "PyC", "Output", "Pdf")
convert(path1, path2)https://stackoverflow.com/questions/72689132
复制相似问题