Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Editing workbooks with rich text in openpyxl

I was wondering if openpyxl can read and/or write rich text into excel. I am aware that this question was asked once before in 2012 linked below, but I am not sure if this has changed.

As it stands load_workbook() seems to throw away rich text formatting.

As for a specific problem, I need to open, edit, and save a workbook where some cells have both superscripted and normal text in one cell. When I save the workbook, the format of the first character of the cell is applied to the rest of the cell.

Here is the to 2012 question:
How do I find the formatting for a subset of text in an Excel document cell

After looking around, it seems like rich text was implemented in openpyxl (based on the issues list on openpyxl's bitbucket):
https://bitbucket.org/openpyxl/openpyxl/issues?q=rich+text

But I am still unclear on how to use it (if I interpreted the issues list correctly at all). If it helps at all, I am actually not editing the contents of these cells simply that they don't lose formatting on save.

Any thoughts would be greatly appreciated.

Thanks! Best

like image 259
fpes Avatar asked Feb 27 '15 21:02

fpes


1 Answers

Formatting below the level of the cell is not supported by openpyxl. To use it you'd have to implement your own code when writing as openpyxl just stores whatever strings it receives. Full read/write support would add a great deal of complexity.

like image 169
Charlie Clark Avatar answered Oct 03 '22 17:10

Charlie Clark