workbook = Workbook()
workbook.LoadFromFile("MS Excel Spreadsheet (2)-test.xls")
# Set the worksheet to adapt to the page during conversion
workbook.ConverterSetting.SheetFitToPage = True
workbook.SaveToFile("Output/ExcelToPDF.pdf", FileFormat.PDF)
workbook.Dispose()
sheets = [
s
for s in workbook.Worksheets
if not s.IsEmpty
and s.Visibility.value == 0 # WorksheetVisibility.Visible
]
for sheet in sheets:
sheet.PageSetup.LeftMargin = 0
sheet.PageSetup.TopMargin = 0
sheet.PageSetup.RightMargin = 0
sheet.PageSetup.BottomMargin = 0
sheet.PageSetup.CenterFooter = ""
sheet.PageSetup.CenterHeader = ""
sheet.PageSetup.LeftFooter = ""
sheet.PageSetup.LeftHeader = ""
sheet.PageSetup.RightFooter = ""
sheet.PageSetup.RightHeader = ""
sheet.PageSetup.IsPrintGridlines = True
sheet_pdf_file = create_tempfile(".pdf")
sheet.SaveToPdf(sheet_pdf_file)