问题修复
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
import pythoncom
|
||||||
from PySide6.QtCore import QObject, Signal
|
from PySide6.QtCore import QObject, Signal
|
||||||
from win32com import client
|
from win32com import client
|
||||||
|
|
||||||
@@ -52,11 +53,14 @@ class DTGWorker(QObject):
|
|||||||
if os.path.exists(pdf_file):
|
if os.path.exists(pdf_file):
|
||||||
os.remove(pdf_file)
|
os.remove(pdf_file)
|
||||||
|
|
||||||
word = client.Dispatch("Word.Application")
|
# https://stackoverflow.com/questions/71292585/python-docx2pdf-attributeerror-open-saveas
|
||||||
doc = word.Documents.Open(word_file)
|
word = client.Dispatch("Word.Application", pythoncom.CoInitialize())
|
||||||
doc.SaveAs(pdf_file, 17)
|
try:
|
||||||
doc.Close()
|
doc = word.Documents.Open(word_file)
|
||||||
word.Quit()
|
doc.SaveAs(pdf_file, 17)
|
||||||
|
doc.Close()
|
||||||
|
finally:
|
||||||
|
word.Quit()
|
||||||
|
|
||||||
os.remove(word_file)
|
os.remove(word_file)
|
||||||
os.startfile(pdf_file)
|
os.startfile(pdf_file)
|
||||||
|
|||||||
Reference in New Issue
Block a user