I need to be able to convert xls into xlsx Files with Python and run the script as an Azure Webjob. I'm able to do the job on my local machine with the following code:
import win32com.client as win32
import os
def xls_2_xlsx(xls_path, xlsx_path):
# Create temp xlsx-File
if os.path.exists(xlsx_path): os.remove(xlsx_path)
excel = win32.DispatchEx("Excel.Application")
excel.Visible = 0
wb = excel.Workbooks.Open(xls_path)
wb.SaveAs(xlsx_path, FileFormat = 51) #FileFormat = 51 is for .xlsx extension
wb.Close()
When running the code as an Azure Webjob i get the following error:
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)
Probably due to the fact that there is (obviously) no Excel installed on the Azure Webjob machine.
I tried other approaches to convert the files as described here: how to convert xls to xlsx
Unfortunately some of the xls-files have cell-values which start with a "+"-sign an get interpreted as a formula, which results in an error. When converting the xls-file cell by cell, the actual value of those cells get lost.
Any help to achieve this task with python as an Azure WebJob would be very appreciated.