How do I save an xlsx file to a pdf?

Hello everyone The question is: how can I save it in PDF format via Excel? Or maybe another way to somehow convert? Here is the code:

try:
    pythoncom.CoInitialize()
    Excel = win32com.client.Dispatch("Excel.Application")
    Excel.Visible = 0
    wb1 = Excel.Workbooks.Open(u'D:\\test.xlsx')
    wb1.SaveAs(u'D:\\test', FileFormat = 6)
    wb1.Close()
except Exception as e:
    print (e)
finally:
    Excel.Quit()

In this code, FileFormat = 6-does the saving in CSV. But through the file format can not be saved to PDF. There is a link to the documentation for possible formats: https://docs.microsoft.com/en-us/office/vba/api/ex... And to FixedFF: https://docs.microsoft.com/en-us/office/vba/api/ex ... SaveAsFixedFormat fails. How is it correct to write a save to PDF? Thanks!

Author: BOMBESKO, 2020-05-11

1 answers

I found it!

wb1.ExportAsFixedFormat(0, 'D:\\test.pdf')
 2
Author: BOMBESKO, 2020-05-11 10:04:47