Domanda

I want to convert xlsx file to xls format using python. The reason is that im using xlrd library to parse xls files, but xlrd is not able to parse xlsx files. Switching to a different library is not feasible for me at this stage, as the entire project is using xlrd, so a lot of changes will be required. So, is there any way i can programatically convert an xlsx file to xls using python ?

Please Help Thank You

È stato utile?

Soluzione

If you're using Python on Windows and you have Excel installed, you could use the Python for Windows Extensions to do it. Here's a sample piece of python code that did the job for me:

import win32com.client

xl = win32com.client.Dispatch("Excel.Application")
xl.DisplayAlerts = False
wb = xl.Workbooks.Open(r"C:\PATH\TO\SOURCE_FILENAME.XLSX")
wb.SaveAs(r"C:\PATH\TO\DESTINATION_FILENAME.XLS", FileFormat = 56)
wb.Close()
xl.Quit()

I tested this using Python 2.7.2 with pywin32 build 216 and Excel 2007 on Windows 7.

Altri suggerimenti

xlrd-0.9.2.tar.gz (md5) can extract data from Excel spreadsheets (.xls and .xlsx, versions 2.0 on-wards) on any platform.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top