这一直困扰着我目前的项目。我正在尝试使用XLWT将样式写入excel表,见下文:
sheet.write(rowi,coli,value,stylesheet.bold,stylesheet.bordered)
我遇到了这个错误:
TypeError:write()最多需要5个参数(给定6个)
知道如何解决这个问题,为某个单元格添加多种样式吗?可以在这里做一个清单吗?
答案 0 :(得分:15)
您应该只将行号,列号,值和样式(XFStyle
类实例)传递给write
方法,例如:
import xlwt
workbook = xlwt.Workbook()
worksheet = workbook.add_sheet('Test')
style = xlwt.XFStyle()
# font
font = xlwt.Font()
font.bold = True
style.font = font
# borders
borders = xlwt.Borders()
borders.bottom = xlwt.Borders.DASHED
style.borders = borders
worksheet.write(0, 0, 'test value', style=style)
workbook.save('test.xls')
同样的事情,但使用easyxf:
import xlwt
workbook = xlwt.Workbook()
worksheet = workbook.add_sheet('Test')
style_string = "font: bold on; borders: bottom dashed"
style = xlwt.easyxf(style_string)
worksheet.write(0, 0, 'test value', style=style)
workbook.save('test.xls')