Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #This is some of the script.
- #I've left out irrelevant parts (dialogboxes etc.) just to make it shorter
- #Import pywin32 and open Excel and selected workbook.
- import win32com.client as win32
- excel = win32.gencache.EnsureDispatch("Excel.Application")
- excel.Visible = False
- wb = excel.Workbooks.Open(wb_path)
- #Select the 1st worksheet in the workbook
- #This is just used for testing
- wb.Sheets([1]).Select()
- #This is the line I can't get to work
- ps_prar = wb.ActiveSheet.PageSetup.PrintArea
- #This is just used to test if I get the print area
- print(ps_prar)
- #This is exporting the selected worksheet to PDF
- wb.Sheets([1]).Select()
- wb.ActiveSheet.ExportAsFixedFormat(0, pdf_path, Quality = 0, IncludeDocProperties = True, IgnorePrintAreas = False, OpenAfterPublish = True)
- #This closes the workbook and the Excel-file (although Excel sometimes still exists in Task Manager
- wb.Close()
- wb = None
- excel.Quit()
- excel = None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement