Editing workbooks with rich text in openpyxl

Question:

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

Asked By: fpes

||

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.

Answered By: Charlie Clark

It is possible, I have used openpyxl to put multiple color in text of the cell.
Please refer this thread for my answer:

Answered By: Nakul
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.