3

After you do:

sheet.write(0, 1, 'whatevs')

Is it still possible to adjust the style of cell 0,1. The reason I am asking is that I have a list of errors I loop and I would like to color all the cells red that have an error.

I could do it when I write the cell but it will make my code a little more complex.

4

1 回答 1

4

没有公开的 API 可以做到这一点,您可以查看源代码并提出一种方法:

rows = ws.get_rows()
rows[0]._Row_cells[0].xf_idx = styleindex 

您可以通过添加您创建的样式来获取样式索引。

style0 = xlwt.easyxf('font: name Times New Roman, color-index red, bold on',
                 num_format_str='#,##0.00')
styleindex = wb.add_style(style0)

wb是 Workbook 对象和ws您的 Worksheet。

当心:这不应该以这种方式完成,但我找不到另一个。

于 2011-08-12T09:31:54.117 回答