7

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.

Ashwin Balamohan
  • 3,303
  • 2
  • 25
  • 47
  • Any reason why the Python Excel libraries (http://www.python-excel.org/) plus the odslib (https://code.google.com/p/odslib-python/) won't work? – BenDundee Mar 06 '13 at 20:18
  • Not at all. I just didn't want to re-invent the wheel if something already existed. I'm happy to write something to do the job and release it to the public, if nothing of the sort exists. – Ashwin Balamohan Mar 06 '13 at 20:30

2 Answers2

10

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.

cwgem
  • 2,739
  • 19
  • 15
1

I succeeded to convert an xlsx file to an ods file with this method :

  1. install pyexcel-xlsx
  2. install pyexcel-ods3

And use the following code :

from pyexcel_ods3 import save_data
from pyexcel_xlsx import get_data

dataXlsx = get_data("file.xlsx")
save_data("file.ods", dataXlsx)

Attention : the colors/design of the xlsx file is removed in the ouput ods file...so that it is not a real success.

AntoineP
  • 3,035
  • 1
  • 19
  • 22