.xlsx and xls(Latest Versions) to pdf using python

Link of xlsxwriter :

https://xlsxwriter.readthedocs.org/en/latest/contents.html

With the help of this you can generate excel file with .xlsx and .xls

for example excel file generated name is trial.xls

Now if you want to generate pdf of that excel file then do the following :

from win32com import client
xlApp = client.Dispatch("Excel.Application")
books = xlApp.Workbooks.Open('C:\\excel\\trial.xls')
ws = books.Worksheets[0]
ws.Visible = 1
ws.ExportAsFixedFormat(0, 'C:\\excel\\trial.pdf')

Leave a Comment