Search code examples
pythonexcelxlrdopenoffice-apiods

Python convert Excel File (xls or xlsx) to/from ODS


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.


Solution

  • 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.