This has been bogging my mind with my current project. I'm trying to write styles into an excel sheet using XLWT, see below:
sheet.write(rowi,coli,value,stylesheet.bold,stylesheet.bordered)
I'm running into this error:
TypeError: write() takes at most 5 arguments (6 given)
Any idea how to get around this to add multiple styles to a certain cell? Is it possible to do a list here?
You should pass only row number, col number, value and style (XFStyle
class instance) to the write
method, for example:
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')
The same thing, but using 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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With