python - XlsxWriter: add color to cells -


i try write dataframe xlsx , give color that. use

worksheet.conditional_format('a1:c1', {'type': '3_color_scale'}) 

but it's not give color cell. , want 1 color cells. saw cell_format.set_font_color('#ff0000') there don't specify number of cells

sex = pd.concat([df2[["all"]],df3], axis=1) excel_file = 'example.xlsx' sheet_name = 'sheet1'  writer = pd.excelwriter(excel_file, engine='xlsxwriter') sex.to_excel(writer, sheet_name=sheet_name, startrow=1) workbook = writer.book worksheet = writer.sheets[sheet_name]  format = workbook.add_format()  format.set_pattern(1) format.set_bg_color('gray') worksheet.write('a1:c1', 'ray', format)  writer.save() 

i need give color a1:c1, should give name cell. how can paint several cells of df?

the problem worksheet.write('a1:c1', 'ray', format) used write single cell. possible solution write more cells in row, use write_row().

worksheet.write_row("a1:c1", ['ray','ray2','ray3'], format) 

remember write_row() takes list of string write in cells.

if use worksheet.write_row("a1:c1", 'ray', format), have r in first cell, a in second , y in third.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -