G
G
Gleb Lukashonok2020-05-11 12:54:02
Python
Gleb Lukashonok, 2020-05-11 12:54:02

How to save xlsx file to pdf?

Hello! The question is: how to save in PDF format through Excel? Or maybe some other way to 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 - makes the save to CSV.
But through the file, the format cannot be saved to PDF.
There is a link to 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 to write save to PDF?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gleb Lukashonok, 2020-05-11
@Bombesko

Found!
wb1.ExportAsFixedFormat(0, 'D:\\test.pdf')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question