Answer the question
In order to leave comments, you need to log in
Why is xlsxwriter not applying align and text_wrap styles?
Hello. There is a code that creates an excel file:
import xlsxwriter
workbook = xlsxwriter.Workbook('formatting.xlsx')
worksheet1 = workbook.add_worksheet()
format1 = workbook.add_format({'align': 'center', 'bg_color': '#FFC7CE', 'font_color': '#9C0006'})
format2 = workbook.add_format({'align': 'center', 'bg_color': '#C6EFCE', 'font_color': '#006100'})
data = [
[34, 72, 38, 30, 75, 48, 75, 66, 84, 86],
[6, 24, 1, 84, 54, 62, 60, 3, 26, 59],
[28, 79, 97, 13, 85, 93, 93, 22, 5, 14],
]
worksheet1.write('A1', 'Cells with values >= 50 are in light red. Values < 50 are in light green.')
for row, row_data in enumerate(data):
worksheet1.write_row(row + 2, 1, row_data)
worksheet1.conditional_format('B3:K12', {
'type': 'cell', 'criteria': '>=',
'value': 50,
'format': format1
})
worksheet1.conditional_format('B3:K12', {
'type': 'cell',
'criteria': '<',
'value': 50,
'format': format2
})
'align': 'center'
(also text_wrap
), but the text needs to be centered. At the same time bg_color
, they font_color
apply. Answer the question
In order to leave comments, you need to log in
Same problem. The author did not understand why centering does not work?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question