在openpyxl中编辑富文本的工作簿 [英] Editing workbooks with rich text in openpyxl

查看:232
本文介绍了在openpyxl中编辑富文本的工作簿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道openpyxl是否可以读取和/或将富文本写入excel。我知道这个问题在2012年之前被提交到下面,但我不知道这是否已经改变。



正如load_workbook()似乎扔掉丰富的文本格式。



对于一个特定的问题,我需要打开,编辑和保存一个工作簿,其中一些单元格在一个单元格中包含上标和正常文本。当我保存工作簿时,单元格的第一个字符的格式将应用于单元格的其余部分。



这是2012年的问题:

如何在Excel文档单元格中找到文本子集的格式



查看周围后,似乎富文本已被实现openpyxl(根据openpyxl的bitbucket上的问题列表):

https://bitbucket.org/openpyxl/openpyxl/issues?q=rich+text



但是我仍然不清楚如何使用它(如果我完全解释了问题列表)。如果它有帮助,我其实不是编辑这些单元格的内容,只是他们不会在保存时丢失格式。



任何想法都将不胜感激。 / p>

谢谢!
最佳

解决方案

openpyxl不支持单元格级别下的格式化。要使用它,您必须在写入时实现自己的代码,因为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

解决方案

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.

这篇关于在openpyxl中编辑富文本的工作簿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆