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

2

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.

Zayas answered 6/3, 2013 at 20:11 Comment(2)
Any reason why the Python Excel libraries (python-excel.org) plus the odslib (code.google.com/p/odslib-python) won't work?Wildfire
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.Zayas
I
11

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.

Imposition answered 6/3, 2013 at 20:52 Comment(3)
Thanks. This looks like a way to go.Zayas
Note that this command does not work if libreoffice is running already.Garrik
If the executable on windows is soffice.exe, then its not working.Nadinenadir
O
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.

Osmometer answered 27/9, 2022 at 10:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.