jdum / odfdo

python library for OpenDocument format (ODF)
Apache License 2.0
48 stars 11 forks source link

Spreadsheet document with style not correctly visualized in LibreOffice #41

Closed SevC10 closed 1 month ago

SevC10 commented 1 month ago

I try to create a new spreadsheet document with some formatting applied to the text (bold text). If I open the generated ods file with Excel, it correctly shows the bold text, while if I open the ods file with LibreOffice, the bold formatting is not present. I know there are issue with styles, but I wonder if a simple case could be fixed.

Thank you! Severino

System information:

Minimal working example:

from odfdo import Document, Table, Style

STILE_GRASS = 'grassetto'

def crea_stile_grassetto(document):

    nome_stile = STILE_GRASS

    style = Style(
        family='text',
        name=nome_stile,
        display_name=nome_stile,
        bold=True,
    )

    document.insert_style(style)

def test_bold_style():

    doc = Document('spreadsheet')

    body = doc.body
    body.clear()

    crea_stile_grassetto(doc)

    nome_foglio = 'test'
    foglio = Table(nome_foglio)

    foglio.set_value((0, 0), 'BOLD', style=STILE_GRASS)
    foglio.set_value((0, 1), 'NO BOLD')

    body.append(foglio)

    file_out = 'test_style.ods'
    doc.save(file_out)

    print(f'saved: {file_out}')

if __name__ == '__main__':
    test_bold_style()
jdum commented 1 month ago

Hi, just change the Style object as:

style = Style(
        family="table-cell",
        area="text",
        name=nome_stile,
        display_name=nome_stile,
        bold=True,
    )
SevC10 commented 1 month ago

It works! Thank you very much for your support! Severino

jdum commented 1 month ago

:-) Programmatically generating styles is hell.