# excel_color.py | ravisdxb@gmail.com | April 2019 from openpyxl import load_workbook # set the variables as required input_file='Book1.xlsx' worksheet='Sheet1' output_file='New-'+input_file color_col=2 # column number where colors are available - 1=A, 2=B .... # instantiate a workbook wb=load_workbook(input_file) #instantiate a worksheet ws=wb[worksheet] # define a new column COLOR after the last column newcol=ws.max_column+1 ws.cell(1,newcol).value='COLOR' # get the color code of required column and put in the new column for i in range(2,ws.max_row+1): ws.cell(i,newcol).value=ws.cell(i,color_col).fill.start_color.index # save to a new file wb.save(output_file)