I had this problem, this is a super simple way to create your PDF documents with Excel, using the win32com.client library:
def xlpdf(self):
app = client.DispatchEx('Excel.Application')
app.Interactive = False
app.Visible = False
# **self.style_sheet** is the Excel workbook previously loaded with openpyxl.loadworkbook
wb = app.Workbooks.open(self.style_sheet)
# **self.style_options.currentText()** is a combobox that already exists, that allows me to choose which page of the book I want to convert to PDF
wb.worksheets(self.style_options.currentText()).Activate()
output = r'Some_dir_path_name.pdf'
wb.ActiveSheet.ExportAsFixedFormat(0, output)
wb.Close()
os.system('taskkill /f /im excel.exe')
I hope it is useful! It serves for many things in a company and saves a lot of time, at least my application is to create PDF's massively.
Traté con otras opciones que son para un objeto asÃ:
import openpyxl
wb = openpyxl.loadworbook('Excel_dirname.xlsx')