[英]How can I get the background color of a cell from an excel file using pandas?
我想知道是否有一種方法可以使用 pandas 從 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.