def highlight_columns(sheetname): dif_items = get_dif_columns(sheetname) excel = Excel(settings.TGT_FILE_PATH) wb = excel.get_wb() ws = excel.get_sheet(sheetname) max_row = excel.get_max_row(sheetname) col_hdr = [] for dif_col in dif_items: col_hdr_item = excel.convert_col2header(sheetname=sheetname, column_name=dif_col) col_hdr.append(col_hdr_item) #print(col_hdr) # for row_nbr in range(1,max_row-490): # for hdr in col_hdr: # cell_item = hdr+str(row_nbr) # print(cell_item) # cell_item.fill = openpyxl.styles.fills.Color. # ws[cell_item].fill = colors.RED # # wb.save('new_compare_result.xlsx') for item in get_dif_columns(sheetname): cells = excel.get_column(sheetname, column_name=item) print(cells) for cell in cells: cell.fill = PatternFill(patternType='solid', fgColor='00FF0000') wb.save('new_compare_result.xlsx')
def setBgColor(sheetname): _getSetList = get_diff_rowdata(sheetname) _filepath = settings.TGT_FILE_PATH _excel = Excel(_filepath) _wb = _excel.get_wb() _ws = _excel.get_sheet(sheetname) for curitem in _ws.iter_rows(): if curitem[0].row in _getSetList: for cell in curitem: cell.fill = PatternFill(fgColor='FF0000', fill_type='solid') _wb.save(settings.END_FILE_PATH)