Is it possible to modify or add to an existing format "on the fly" in xlsxwriter? I'd like this functionality so I can maintain a few primary formats and add new criteria on a case by case basis.
For example in the code below I'd like to add an underline format to the dark_blue_header_format in cell A2 only. However, this produces some unexpected results, which are shown in the picture below. I expected A1 and A3 to be blue with 24-size white text: and I expected A2 to be blue with 24-size white text and underlined.
import xlsxwriter
workbook = xlsxwriter.Workbook('demo.xlsx')
worksheet = workbook.add_worksheet()
dark_blue_header_format = workbook.add_format({
'bg_color': '#5081BB',
'font_color': '#FFFFFF',
'font_size': 24
})
worksheet.set_column('A:A', 30)
worksheet.write('A1', 'Company Name', dark_blue_header_format)
worksheet.write('A2', 'Underlined Company Name', dark_blue_header_format.set_underline())
worksheet.write('A3', 'Company Name', dark_blue_header_format)
workbook.close()
I've looked through the formatting docs and I haven't found anything that can add formats on the fly. If the set_whatever
functionality behaves like this example then I don't understand what it's useful for.
If it isn't possible to add formatting to existing formats "on the fly" what is the best practice when building many unique formats?
Thanks!