Page 1 of 1

[Dropped] Format cells in *.ods using ezodf (Python)

Posted: Wed Jun 18, 2025 5:55 am
by glesco
I am hoping someone can help me out.

I have created a Python program to do simple but repetitive calculations using "while loops." Using the "ezodf" module I am able to pull the raw data in from a *.ods and write the results in to the *.ods. Works great!

My question is for anyone out there, when writing the results, can I do some some basic formatting in the *.ods cells?
In particular, I wish to:
a) Right align some text cells
b) Set decimal places for some numeric cells
c) Bold some cells
d) Merge and center and bold certain cells

Any help would be appreciated. Thanks in advance!

Re: Formatting cells in an *.ods using the Python "ezodf" module

Posted: Fri Jun 20, 2025 6:09 pm
by Villeroy
Pseudo-code:

Code: Select all

objRanges.CellStyle = 'My Sophisticated Cell Style'
Works just as well with collections of cell ranges.
Not working with templates and styles means ignoring the core functionality of an office suite.

Re: Formatting cells in an *.ods using the Python "ezodf" module

Posted: Thu Jun 26, 2025 8:57 pm
by glesco
Thanks for the reply but unfortunately I am still having problems.

To assign a value to a particular cell I use
Sheet[x,y].set_value(mycalculatedvalue) where x & y are the coordinates in the sheet.

How would a assign a format to that cell? I have tried Sheet[x,y].set_style() and Sheet[x,y].set_format() but neither seems to work.

Thanks for any help.

Re: Formatting cells in an *.ods using the Python "ezodf" module

Posted: Thu Jun 26, 2025 9:44 pm
by MrProgrammer
glesco wrote: Thu Jun 26, 2025 8:57 pm I have tried Sheet[x,y].set_style() and Sheet[x,y].set_format() but neither seems to work.
Where did you get the idea that you could use set_style() and set_format() in ezodf? Are you just guessing how to use it? That approach will take you a lifetime. You should read its documentation.
Search finished, found 13 page(s) for style at pythonhosted.org/ezodf

You can write macros in Python, but ezodf isn't the standard way to do that. I only find two topics on the forum which mention it. I don't think either project was successful. Search for them and read them. You will find many topics on the forum about Python though. I don't use Python but I think Villeroy's example above is using the standard Python interface, not ezodf. I cannot offer any further assistance with Python programming.