python识别颜色1007python识别颜色_使用XLRD包识别Excel Sheet单元格颜色代码

I am writing a python script to read data from an excel sheet using xlrd. Few of the cells of the the work sheet are highlighted with different color and I want to identify the color code of the cell. Is there any way to do that ? An example would be really appreciated.

解决方案

Here is one way to handle this:

import xlrd

book = xlrd.open_workbook("sample.xls", formatting_info=True)

sheets = book.sheet_names()

print "sheets are:", sheets

for index, sh in enumerate(sheets):

sheet = book.sheet_by_index(index)

print "Sheet:", sheet.name

rows, cols = sheet.nrows, sheet.ncols

print "Number of rows: %s Number of cols: %s" % (rows, cols)

for row in range(rows):

for col in range(cols):

print "row, col is:", row+1, col+1,

thecell = sheet.cell(row, col)

# could get 'dump', 'value', 'xf_index'

print thecell.value,

xfx = sheet.cell_xf_index(row, col)

xf = book.xf_list[xfx]

bgx = xf.background.pattern_colour_index

print bgx

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值