I have an Excel file with cells having background colors. I am reading that file into pandas with read_excel
. Is there any way to get the background colors of cells?
我有一个带有背景颜色的单元格的Excel文件。我正在使用read_excel将该文件读入pandas。有没有办法获得细胞的背景颜色?
1 个解决方案
#1
2
Brute-forced it through xlrd
, as per Mark's suggestion:
根据马克的建议,通过xlrd强制执行它:
from xlrd import open_workbookwb = open_workbook('wb.xls', formatting_info=True)sheet = wb.sheet_by_name("mysheet")#create empy colormask matrixbgcol=np.zeros([sheet.nrows,sheet.ncols])#cycle through all cells to get colorsfor row in range(sheet.nrows): for column in range(sheet.ncols): cell = sheet.cell(row, column) fmt = wb.xf_list[cell.xf_index] bgcol[row,column]=fmt.background.background_colour_index#return pandas mask of colorscolormask=pd.DataFrame(bgcol)
Yet, there must be a better way thorugh pandas directly...
然而,必须有一个更好的方式直接熊猫...
#1
2
Brute-forced it through xlrd
, as per Mark's suggestion:
根据马克的建议,通过xlrd强制执行它:
from xlrd import open_workbookwb = open_workbook('wb.xls', formatting_info=True)sheet = wb.sheet_by_name("mysheet")#create empy colormask matrixbgcol=np.zeros([sheet.nrows,sheet.ncols])#cycle through all cells to get colorsfor row in range(sheet.nrows): for column in range(sheet.ncols): cell = sheet.cell(row, column) fmt = wb.xf_list[cell.xf_index] bgcol[row,column]=fmt.background.background_colour_index#return pandas mask of colorscolormask=pd.DataFrame(bgcol)
Yet, there must be a better way thorugh pandas directly...
然而,必须有一个更好的方式直接熊猫...