![](/img/trans.png)
[英]Reading colours of cell in an excel sheet using python: openpyxl or any other library
[英]Is there any way to while reading from excel file get style of each word inside cell using openpyxl python
我正在尝试解析 excel 文件,然后在解析 excel 数据后创建 JSON。 excel 可能包含使用粗体、斜体等样式的单词。我使用 openpyxl 获取格式,但它用于整个单元格。 如果单元格包含一个单词为粗体/斜体或彩色的句子,则无法获取样式。
如果有人可以指导我这将非常有帮助
提前致谢
我能想到的唯一且相当乏味的方法是提取 xlsx 文件(它只是一个 zip 存档)并修改其中的sharedStrings.xml
(例如使用 ElementTree)。 然后将文件压缩回一起。
该方法描述如下:
https://stackoverflow.com/a/53454150/7919597
例如对于像这样的细胞
sharedStrings.xml
看起来像
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="1" uniqueCount="1">
<si>
<r>
<rPr>
<sz val="11"/><color rgb="FFFF0000"/><rFont val="Calibri"/><family val="2"/>
<scheme val="minor"/>
</rPr>
<t xml:space="preserve">Some Text</t>
</r>
<r>
<rPr>
<sz val="11"/><color theme="7" tint="-0.249977111117893"/><rFont val="Calibri"/><family val="2"/><scheme val="minor"/>
</rPr>
<t>Another Text</t>
</r>
</si>
</sst>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.