您的位置:首页 > 编程语言 > Python开发

使用XLRD包识别Excel工作表单元格颜色代码-python,excel,xlrd-...

2016-08-19 13:48 2286 查看
 

 

使用XLRD包识别Excel工作表单元格颜色代码

 

使用XLRD包识别Excel工作表单元格颜色代码-python,excel,xlrd-...

我写一个python脚本来读取从Excel
xlrd数据。几个工作表中的单元格突出显示不同的颜色,我想找出单元格的颜色代码。有没有办法做到这一点?一个例子将是非常赞赏。...
python excel
xlrd

我写一个python脚本来读取从Excel xlrd数据。几个工作表中的单元格突出显示不同的颜色,我想找出单元格的颜色代码。有没有办法做到这一点?一个例子将是非常赞赏。

本文地址 :CodeGo.net/374850/
-------------------------------------------------------------------------------------------------------------------------
1. 这里有一个方法来处理这个问题:

import xlrd
book = xlrd.open_workbook("sample.xls", formatting_info=1)
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

在Python中的Excel谷歌集团

本文标题 :使用XLRD包识别Excel工作表单元格颜色代码

本文地址
4000
:CodeGo.net/374850/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: