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

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

问题描述

我想知道 openpyxl 是否可以在 excel 中读取和/或写入富文本.我知道这个问题在 2012 年之前曾被问过一次,链接如下,但我不确定这是否已经改变.

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.

目前的 load_workbook() 似乎抛弃了富文本格式.

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.

这是 2012 年的问题:
如何在 Excel 文档单元格中找到文本子集的格式

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

环顾四周,似乎在openpyxl中实现了富文本(基于openpyxl的bitbucket上的问题列表):
https://bitbucket.org/openpyxl/openpyxl/issues?q=rich+text

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.

谢谢!最好的

推荐答案

openpyxl 不支持单元格级别以下的格式.要使用它,您必须在 编写 时实现自己的代码,因为 openpyxl 只存储它接收到的任何字符串.完整的读/写支持会增加很多复杂性.

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天全站免登陆