在python(xlwt)中设置excel列样式

我正在尝试将数据写入Excel文档,其中一些列完全由我想格式化的date/数字数据组成。 我可以分别在每个单元格上设置一个格式,但似乎过多。 对象列上有一个set_style方法,但由于某种原因,它似乎没有做任何事情。

 import xlwt from datetime import date book = xlwt.Workbook('ascii') sheet = book.add_sheet('Sheet1') # cells in first column, they end up with no formatting sheet.write(0, 0, date(2012, 1, 1)) sheet.write(1, 0, date(2012, 1, 1)) sheet.write(2, 0, date(2012, 2, 1)) style = xlwt.easyxf(num_format_str='YYYY-MM-DD') sheet.col(0).set_style(style) # cells in second column are formatted correctly sheet.write(0, 1, date(2012, 1, 1), style) sheet.write(1, 1, date(2012, 1, 1), style) sheet.write(2, 1, date(2012, 2, 1), style) book.save(open('foo.xls', 'wb')) 

希望这可以帮助: 类似于你的问题

我已经看到这用于循环,有效的使用。