0

I have a list of list like

x=[['My??50','Name??70','is??90'],['this??90','is??80','another??40','line??70'],['lets??90','take??90','another??90','line??70']]

I want to write this into a excel/csv file. The condition is i want to write the text present before the '??' only in excel file. The number behind the '??' will be used to check if the cell should be coloured or not. If the number behind '??' is less than 90 i want to colour it red. e.g.,

text='My??50'.split('??')[0]
number=int('My??50'.split('??')[-1])
if number<90:
   write(text with colour red)

I was trying to use Styler in pandas but it did not workout.

Saad
  • 916
  • 1
  • 15
  • 28
user3809411
  • 326
  • 1
  • 3
  • 19

1 Answers1

0

I was able to resolve this,

from xlwt import Workbook
import xlwt
book = Workbook()
sheet1 = book.add_sheet('Sheet 1')

x=[['My??50','Name??70','is??90'],['this??90','is??80','another??40','line??70'],
   ['lets??90','take??90','another??90','line??70']]


st = xlwt.easyxf('pattern: pattern solid;')
st.pattern.pattern_fore_colour = 20
for i, l in enumerate(x):
    for j, col in enumerate(l):
        print(col)
        if int(col.split('??')[-1])<85:
            sheet1.write(i, j, col.split('??')[0],st)
        else:
            sheet1.write(i, j, col.split('??')[0])
book.save('C:\\Users\\sandeep.sharma\\Desktop\\vishal\\data\\simple.xls')
user3809411
  • 326
  • 1
  • 3
  • 19