This code below helps to print worksheets (1,2,4) into 3 separate PDF file.
The issue is, it take sheet as order (1,2,4) instead of sheet name.
If I want to print 3 sheets with name: Mysheet1, yoursheet, hersheet, how can I print them to pdf?
Can you please help?
Thanks HR
import win32com.client
o = win32com.client.Dispatch("Excel.Application")
o.Visible = False
# Path to Excel file
wb_path = r'C:\tempfile/Sample Invoice.xlsx'
# Open this Excel file
wb = o.Workbooks.Open(wb_path)
# list the sheet you want to print, first sheet is 1, use sheet order, not actual sheet name
ws_index_list = [1,2,4]
for i in ws_index_list:
path_to_pdf = fr'C:\tempfile/sample{i}.pdf'
wb.WorkSheets(i).Select()
wb.ActiveSheet.ExportAsFixedFormat(0, path_to_pdf)