Here is an example: Generate Excel formatting file directly in Python
Note that you create a font object and then pass it to the style object, and then provide that style object when writing to the sheet:
import pyExcelerator as xl
def save_in_excel(headers,values):
mydoc=xl.Workbook()
mysheet=mydoc.add_sheet("test")
header_font=xl.Font()
header_font.bold=True
header_font.underline=True
header_style = xl.XFStyle(); header_style.font = header_font
for col,value in enumerate(headers):
mysheet.write(0,col,value,header_style)
highlighted_row_font=xl.Font()
highlighted_row_font.bold=True
highlighted_row_font.colour_index=2
highlighted_row_style = xl.XFStyle(); highlighted_row_style.font = highlighted_row_font
for row_num,row_values in enumerate(values):
row_num+=1
if row_values[1]=='Manatee':
for col,value in enumerate(row_values):
mysheet.write(row_num,col,value,highlighted_row_style)
else:
for col,value in enumerate(row_values):
mysheet.write(row_num,col,value)
mydoc.save(r'C:testpyexel.xlt')
headers=['Date','Name','Localatity']
data=[
['June 11, 2006','Greg','San Jose'],
['June 11, 2006','Greg','San Jose'],
['June 11, 2006','Greg','San Jose'],
['June 11, 2006','Greg','San Jose'],
['June 11, 2006','Manatee','San Jose'],
['June 11, 2006','Greg','San Jose'],
['June 11, 2006','Manatee','San Jose'],
]
save_in_excel(headers,data)