Editing workbooks with rich text in openpyxl

1,109 views
Skip to first unread message

soll...@gmail.com

unread,
Feb 27, 2015, 7:14:32 PM2/27/15
to openpyx...@googlegroups.com
Hi,

I was wondering if openpyxl can read and/or write rich text into excel. As it stands load_workbook() seems to throw away rich text formatting. For example, 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.

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


Charlie Clark

unread,
Mar 1, 2015, 6:31:51 AM3/1/15
to openpyx...@googlegroups.com
Am .02.2015, 01:14 Uhr, schrieb <soll...@gmail.com>:

> Hi,
> I was wondering if openpyxl can read and/or write rich text into excel.

No, and there are no plans to support it.

> As
> it stands load_workbook() seems to throw away rich text formatting. For
> example, 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.

We preserve the text just not the formatting below the level of the 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.

The problem is trying to make the contents accessible from Python almost
mandates throwing the formatting away. To support involves adding a *lot*
of complexity as the number of ways text can be stored goes up to 4.

Charlie
--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Kronenstr. 27a
Düsseldorf
D- 40217
Tel: +49-211-600-3657
Mobile: +49-178-782-6226
Reply all
Reply to author
Forward
0 new messages