You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
xlsx 转 PDF 报错: File "<COMObject <unknown>>", line 3, in ExportAsFixedFormat ? #105
import poexcel
if __name__ == '__main__':
poexcel.excel2pdf(excel_path=r".\m1.xlsx",pdf_path=r".\test.pdf")
exec result
files amount:1
files amount:1
Traceback (most recent call last):
File "C:\Users\xxx\python_project\xlsx2pdf\main.py", line 6, in <module>
poexcel.excel2pdf(
File "C:\Users\xxx\python_project\xlsx2pdf\venv\lib\site-packages\poexcel\api\excel.py", line 58, in excel2pdf
mainExcel.excel2pdf(excel_path, pdf_path, sheet_id)
File "C:\Users\xxx\python_project\xlsx2pdf\venv\lib\site-packages\poexcel\core\ExcelType.py", line 162, in excel2pdf
sheet.to_pdf(path=pdf_path_name, show=False)
File "C:\Users\xxx\python_project\xlsx2pdf\venv\lib\site-packages\xlwings\main.py", line 1569, in to_pdf
return self.book.to_pdf(
File "C:\Users\xxx\python_project\xlsx2pdf\venv\lib\site-packages\xlwings\main.py", line 1275, in to_pdf
return utils.to_pdf(
File "C:\Users\xxx\python_project\xlsx2pdf\venv\lib\site-packages\xlwings\utils.py", line 662, in to_pdf
obj.impl.to_pdf(os.path.realpath(report_path), quality=quality)
File "C:\Users\xxx\python_project\xlsx2pdf\venv\lib\site-packages\xlwings\_xlwindows.py", line 920, in to_pdf
self.xl.ExportAsFixedFormat(
File "C:\Users\xxx\python_project\xlsx2pdf\venv\lib\site-packages\xlwings\_xlwindows.py", line 122, in __call__
v = self.__method(*args, **kwargs)
File "<COMObject <unknown>>", line 3, in ExportAsFixedFormat
####----- Error when run from Tk UI -----####
#File "C:\Users\dengm\OneDrive\Program\Work\JDOC-CSV\Excel2PDF_win32com.py", line 57, in
#wb.ActiveSheet.ExportAsFixedFormat(0, pdf_filename)
#File "<COMObject >", line 4, in ExportAsFixedFormat
#pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', 'Document not saved. The document may be open, or an error may have been encountered when saving.', 'xlmain11.chm', 0, -2146827284), None)
#when hard-coded the input <filename> as the following, it works!!!
#filename = r"C:\Users\dengm\Downloads\New folder\02_Workflow-Doc Creation Notification_Unexecuted.xlsx"
#this is a file path issue for wb.ActiveSheet.ExportAsFixedFormat!!
#--- just give the file name for <pdf_filename> without path, it works to convert to pdf, save to the default folder "Documents" of the user: os.path.expandvars("%userprofile%\\Documents")
Activity
michaeldengxyz commentedon Dec 30, 2024
####----- Error when run from Tk UI -----####
#File "C:\Users\dengm\OneDrive\Program\Work\JDOC-CSV\Excel2PDF_win32com.py", line 57, in
#wb.ActiveSheet.ExportAsFixedFormat(0, pdf_filename)
#File "<COMObject >", line 4, in ExportAsFixedFormat
#pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', 'Document not saved. The document may be open, or an error may have been encountered when saving.', 'xlmain11.chm', 0, -2146827284), None)
####----- Error when run from Tk UI -----####