Home » excel » put style and background color python excel

put style and background color python excel

Posted by: admin April 23, 2020 Leave a comment

Questions:

i want to make excel value to center align and have a yellow background color. But i can’t input too many arguments. So i try this one but it’s nothing happen. Is there any other way to do it?

colorCenter = xlwt.XFStyle()

xlwt.add_palette_colour("custom_colour", 0x21)
wb.set_colour_RGB(0x21, 255, 255, 0)
color = xlwt.easyxf('pattern: pattern solid, fore_colour custom_colour')

colorCenter.color = color

alignment = xlwt.Alignment()
alignment.horz = xlwt.Alignment.HORZ_CENTER
center = xlwt.XFStyle()

colorCenter.center = center

sheet.write(11, 3, 'value', colorCenter)
How to&Answers:

use easyxf is the best. you can put align, font, and pattern

colorCenter = easyxf('pattern: pattern solid, fore_colour yellow;'
                      'align: horiz center;')