Python - How can I update an ODS file without losing the formatting

663 Views Asked by At

In my project, I'm using Python with the library pyexcel-ods3 and I need to change the value of some cells in my ods file.

I manage to do it but every parameter I put in cells such as the color, the merging ect have been reset.

Here's the code

from pyexcel_ods3 import get_data
from pyexcel_ods3 import save_data
from collections import OrderedDict

def get_data_file(file):
    return get_data(file)

def write_cell_sheet(filename, sheet, line, column, donnees_file, new_value):
    donnees_file[sheet][int(line) - 1][int(column) - 1] = new_value
    save_data(filename, donnees_file)

donnees_file = get_data_file(odsfile)
write_cell_sheet(odsfile, "Sheet1", 5, 5, donnees_file, "HELLO")

This code does not come from my projet but it shows how do I update my ods file.

Here's 2 picture of the corresponding file to better describe my problem

Before update :

enter image description here

After update :

enter image description here

If someone knows how can I update my ods file without losing the formatting, I would be very glad to know.

0

There are 0 best solutions below