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

Java, C++, C#, Delphi... - Using the UNO bridges
Locked
glesco
Posts: 2
Joined: Wed Jun 18, 2025 5:10 am

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

Post 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!
Last edited by MrProgrammer on Mon Jul 07, 2025 4:15 pm, edited 1 time in total.
Reason: Dropped: No reply from glesco
OpenOffice 4.1.15 on Windows 10
User avatar
Villeroy
Volunteer
Posts: 31348
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Post 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.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
glesco
Posts: 2
Joined: Wed Jun 18, 2025 5:10 am

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

Post 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.
OpenOffice 4.1.15 on Windows 10
User avatar
MrProgrammer
Moderator
Posts: 5322
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

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

Post 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.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.6, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
Locked