Printing Excel Worksheets with COM Interface

I programmatically made a bunch of Excel sheets with xlwt in python. Everything went well, but now I need to convert them all to pdf. I tried to do this using pywin32 and the com interface. I can come a little closer to this:

import win32com.client
o = win32com.client.Dispatch("Excel.Application")
o.Visible = 1
wb = o.Workbooks.Open('foo.xls')
ws = wb.Worksheets[1]
ws.printout()

But, unfortunately, when I do this, it pops up on the adobe printer screen, asking me for the path that I want to save in pdf, and if I need to enter this or click ok for each page, it will defeat the goal of doing this programmatically. Is there a way that I can enter this path into python code and not manually? Is there a better way to convert each of these sheets in each of these books to pdf? Thanks a lot, Alex

+5
source share
2 answers

PrintOut ExportAsFixedFormat. pdf . :

ws.ExportAsFixedFormat(0, 'c:\users\alex\foo.pdf')
+5

PDF PDF. .

0

All Articles