python excel 单元格格式_如何使用Python从Excel文件中提取单元格格式(粗体,斜体等)?...

I'm trying to extract from an Excel file the content of a cell (essentially text) and the format of the text. The Excel I am dealing with looks like the screenshot below :

Texts in cells may be bold, italic or stroke and I need to extract the text and the format into a python string. For example, if a cell contains :

line 1

line 2

line 3

I would like to obtain a string Python that's look like :

- line 1 /n- **line 2**/n- *line 3**

in order to get the text and the format information.

I've tried to find a solution using openpyxl, but it seems that it is only possible to apply and not extract format cell. Library xlrd seems not fitted for xlsx. I am currently trying with pyexcel library.

Do you have any idea ? Thanks.

解决方案

You can import Font from openpyxl and check if a cell is written in bold by using cell.font.bold, it gives a True or False.

cell=sheet[A2]

bold_status=cell.font.bold

italic_status=cell.font.italic

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值