I've been scouring the net to find a Python library or tool that can converts an Excel file to/from ODS format, but haven't been able to come across anything.
I need the ability to input and output data in either format. We don't need to worry about merged cells, formulas or anything non-straightforward.
openpyxl is a Python library to read/write Excel 2010 xlsx/xlsm/xltx/xltm files.
To convert xls to xlsx: $ pip install pyexcel pyexcel-xls pyexcel-xlsx. Run Python Script as: import pyexcel as p p.save_book_as(file_name='your-file-in.xls', dest_file_name='your-new-file-out.xlsx') If you do not need a program, you could install one additinal package pyexcel-cli::
Before reading the ODS files with Python we need to install additional packages like: odfpy + Pandas (if not installed or upgrade to latest). To install odfpy + Pandas use next commands: Now we can read the first sheet of the worksheet by calling Pandas method read_excel ():
You didn't say which platform you are using, but if it's Windows or Mac, and you have Excel installed, then the most straightforward way to automate Excel is probably xlwings. In principle this will allow you to use Python to open the .xlsx file in Excel (an actual, running instance of Microsoft Excel) and do "save as" to a .xls file.
To convert xls to xlsx: If you do not need a program, you could install one additinal package pyexcel-cli:: The transcoding procedure above uses xlrd and openpyxl. 2. To convert between xlsx and xls vice and versa: You need to have win32com installed on your machine.
If you have libreoffice installed, you can do a python execution wrapper around its headless mode:
$ /usr/bin/libreoffice --headless --invisible -convert-to ods /home/cwgem/Downloads/QTL_Sample_data.xls
convert /home/cwgem/Downloads/QTL_Sample_data.xls -> /home/cwgem/QTL_Sample_data.ods using OpenDocument Spreadsheet Flat XML
$ /usr/bin/libreoffice --headless --invisible -convert-to xls /home/cwgem/QTL_Sample_data.ods
convert /home/cwgem/QTL_Sample_data.ods -> /home/cwgem/QTL_Sample_data.xls using
Which would be a bit easier than trying to do it through the library route.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With