如何使用熊猫从 excel 文件中获取单元格的背景颜色?



我想知道是否有办法使用熊猫从 excel 文件中获取单元格的背景颜色?

谢谢!

xlrd 和 Numpy 的组合可以帮助您检索单元格背景颜色。希望此示例代码对您有所帮助

import xlrd
import numpy as np
workbk = xlrd.open_workbook(file, formatting_info=True)
sheet = workbk.sheet_by_name("sheet_name")
bgcol=np.zeros([sheet.nrows,sheet.ncols])
for row in range(sheet.nrows):
for col in range(sheet.ncols):
c = sheet.cell(row, col)
cif = sheet.cell_xf_index(row, col)
iif = wb.xf_list[cif]
cbg = iif.background.pattern_colour_index
bgcol[row,col] = cbg

最新更新