简体   繁体   中英

Is there a way to create an excel file to a PDF but in a landscape orientation in python?

def PDF():
    
    # Open Microsoft Excel
    excel = win32com.client.Dispatch("Excel.Application")
    
    # Read Excel File
    sheets = excel.Workbooks.Open('Logbook.xlsx')
    work_sheets = sheets.Worksheets[0]
  
    # Convert into PDF File
    work_sheets.ExportAsFixedFormat(0, 'Logbook.pdf')

i have the this code to save an excel file as a PDF but when it saves it saves as multiple pages with the spreadsheet being cut in half, is there any possible way to change the orientation to landscape using python? BTW i'm quite new with python so any help is much appreciated

You can look up most of this stuff by searching for "excel object model orientation".

work_sheets.PageSetup.Orientation = win32com.client.constants.xlLandscape

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM