python-office
python-office copied to clipboard
xlsx 转 PDF 报错: File "<COMObject <unknown>>", line 3, in ExportAsFixedFormat ?
my project dir
- m1.xlsx
- main.py
this main.py code
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
#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")
####----- Error when run from Tk UI -----####