Creating a Calc sheet from python

Hi,

I’m looking for a well maintained way to create a Calc sheet from a python script, that is:

  • open the ODS file
  • add a new sheet with data in it
  • save the ODS file

I found a few modules such as odfpy or ezodf (no longer maintained, last commit is 2017) but it is unclear which one is best suited to this purpose. There also is a 2015 question that is almost similar to mine but it is ancient by Python standards.

Although I’ve been able to create a Calc sheet using the ezodf example it does not sound like a solution. If the module faces a critical bug next week for any reason, there will be no fix because it is not maintained.

Thanks in advance for your help !

Instead of a third-party library, have you considered Python-UNO? LibreOffice has an API, and it comes with Python support. Otherwise, if you do not plan to use LibreOffice in your script, then your question may be off-topic for this site. Personally, I do not use such third-party libraries, and I’m not sure others on this site do either.

The only downside of UNO is the need to run a libreoffice headless server. But that’s ok :slight_smile: Thanks!

Hi…

For open look:
https://wiki.documentfoundation.org/Macros/Python_Guide/Documents#Open

For add new sheet:
https://wiki.documentfoundation.org/Macros/Python_Guide/Calc/Calc_sheets#Insert

For save ODS

doc.store()

Best regards

UNO is a little bit complex to use but stable. Excellent find!