title: Color specific excel cells based on match condition in python
body: <p>I got an excel sheet with weekly data for number of people</p>
  
  <pre><code>Sam    Tony   Michael 
  10      34      25
  10      22      25
  10      22      33
  10      22      33
  </code></pre>
  
  <p>Requirement is to compare the rows with first value in their respective column and then color the cells which do not match the first row value in their columns</p>
  
  <p>I have been able to write code to find different values, however unable to color those cells</p>
  
  <pre><code>import xlrd
  import xlwt
  from xlwt import Workbook
  from xlrd import open_workbook
  wb = open_workbook("test1.xlsx")
  mysheet = wb.sheet_by_name('Sheet1')
  numrows = mysheet.nrows
  value = ""
  value1 = ""
  
  col = 0
  st = xlwt.easyxf('pattern: pattern solid;')
  st.pattern.pattern_fore_colour = 1
  while col &lt; 200:
          value = mysheet.cell(1 , col)
          for y in range(numrows-1):
                  y +=1
                  value1 = mysheet.cell(y , col)
                  value = str(value)
                  value1 = str(value1)
  
                  if (value1 != value):
                          &lt;Colour the cell&gt;  &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;
                  else:
                          continue
          col +=1
  </code></pre>
  
  <p>Also not sure if the same input sheet's cell colors can be changed or have to create a new one</p>
  
  <h1>EDIT 1:</h1>
  
  <p>I tried following, however I am unable to open the file from the format in which python is saving:</p>
  
  <pre><code>import xlrd
  import xlwt
  from xlutils.copy import copy
  from xlwt import Workbook
  from xlrd import open_workbook
  file_path = '/home/zoro/test1.xlsx'
  rb = open_workbook(file_path, formatting_info=True)
  mysheet = rb.sheet_by_name('Sheet1')
  numrows = mysheet.nrows
  numcols = mysheet.ncols
  value = ""
  value1 = ""
  z = 1
  col = 0
  wb = copy(rb)
  w_sheet = wb.get_sheet(0)
  st = xlwt.easyxf('pattern: pattern solid;')
  st.pattern.pattern_fore_colour = 1
  while col &lt; numcols:
          value = mysheet.cell(z , col)
          for y in range(numrows-1):
                  y +=1
                  value1 = mysheet.cell(y , col)
                  value = str(value)
                  value1 = str(value1)
  
                  if (value1 != value):
                          w_sheet.write(y,col,value1,st)
                  else:
                          continue
          col +=1
  
  wb.save(file_path)
  </code></pre>