I am trying to style specific rows and columns.
worksheet.cell(row=file_row_number, column=1).value = "Hotel ID"
_cell = worksheet.cell("C1")
_cell.style.font.bold = True
It shows me error
TypeError: cannot set bold attribute
Previously I was using XLWT
and it had very easy method of applying styles like you define style
variable once and then for ever write()
yo can just pass the style
variable to apply style on that row/column
Is there any way in OpenPyXL
to apply style easily as I mentioned above?
This has changed since the accepted answer was given.
If you do what the accepted answer suggests, you will receive this warning: UserWarning: Use formatting objects such as font directly warn("Use formatting objects such as font directly")
The answer still works but the new solution would be to apply it to the cell directly, for example:
worksheet.cell("C1").font = Font(bold=True)
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