openpyxl中一个单元格中的多种样式 [英] Multiple styles in one cell in openpyxl

查看:503
本文介绍了openpyxl中一个单元格中的多种样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个Python程序,该程序使用openpyxl将特定格式的发票生成为.xlsx文件.我拥有一般发票表单作为Excel工作簿,我的程序复制了此表单并填写了从另一个.txt文件读取的有关特定客户的详细信息(例如,客户推荐编号,价格等).

该程序运行完美.唯一的问题是表单包含具有多种样式的单元格:一半字母为红色,其余字母为黑色,并且还有大小差异.在我的程序中未对其进行编辑(所有发票均相同),但是在我的程序中编辑了其余工作表后,该单元仅保留了第一种样式(红色字母). /p>

为什么openpyxl会更改此单元格,因为我不对其进行编辑? openpyxl是否支持多种样式,还是我必须在不同的单元格中拆分具有不同样式的字母?

解决方案

openpyxl在单个单元格内不支持多种样式.

I wrote a Python program which produces invoices in a specific form as .xlsx files using openpyxl. I have the general invoice form as an Excel workbook and my program copies this form and fills up the details about the specific client (eg. client refernce number, price, etc.) which are read from another .txt file.

The program works perfectly. The only problem is that the form contains a cell which has multiple styles: half of the letters are red and the rest black and there is also size difference. This cell is not edited in my program (it is the same in all the invoices), however after the rest worksheet is edited by my program the cell keeps only the first style (the red letters).

Why does openpyxl changes this cell since I don't edit it? Does openpyxl support multiple styles, or I have to split the letters with different styles in seperate cells?

解决方案

openpyxl does not support multiple styles within an individual cell.

这篇关于openpyxl中一个单元格中的多种样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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