T0ha / ezodf

ezodf is a Python package to create new or open existing OpenDocument (ODF) files to extract, add, modify or delete document data, forked from dead project https://bitbucket.org/mozman/ezodf
Other
61 stars 23 forks source link

how to assign styles to columns in a table in a odt file ? #16

Closed crc16 closed 8 years ago

crc16 commented 8 years ago

Hello, I would like to add a table in a odt file with columns with precise dimensions using existing styles in this file as already done for an existing table.

<text:p text:style-name="P21"/><table:table table:name="Exigence" table:style-name="Exigence"><table:table-column table:style-name="Exigence.A"/><table:table-column table:style-name="Exigence.B"/><table:table-column table:style-name="Exigence.C"/><table:table-column table:style-name="Exigence.D

I can assign a style to a cell in a table creates :

table = ezodf.Table(size=(1, 4))
table.set_cell(pos=(0,0),cell=ezodf.Cell(style_name="Exigence.A1"))

So how can I assign a style in the columns?

T0ha commented 8 years ago

Hi crc16,

If you have existing cell (row or column) with style you want, it's better to copy styles.

table = Table(..) #Some existing table# 
# col1, row1 - existing cell coordinates
cell1 = table[(row1, col1)] # Existing cell with style
# col2, row2 - new cell coordinates
cel2 = table[(row2, col2)]
cell2.set_value('New cell')
cell2.style_name = cell1.style_name
table.row_info(row2).style_name = table.row_info(row1).style_name
table.column_info(col2).style_name = table.column_info(col1).style_name

Something like this.

crc16 commented 8 years ago

Hi T0ha Ok, that works very well Thank you

T0ha commented 8 years ago

Happy to help you.