eea / odfpy

API for OpenDocument in Python
GNU General Public License v2.0
308 stars 63 forks source link

How to make a table wrap its contents? #51

Open rafpyprog opened 7 years ago

rafpyprog commented 7 years ago

Is it possible optimize the size of the columns inside a table in an ods documment, wrapping the text?

cityy commented 5 years ago

Edit: I had been on a wrong track earlier but this solution works for me as stated in the corrected post below.

I'm trying to do this as well and figured that wrapping is handled by styles of the table-cell family using the wrapoption attribute. wrapoption is only available within TableCellProperties().

    wordwrap = Style(name="wordwrap", family="table-cell")
    wordwrap.addElement(TableCellProperties(wrapoption="wrap"))
    document.styles.addElement(wordwrap)

Now apply the style to your TableCell() element.