79693001

Date: 2025-07-07 14:30:32
Score: 1
Natty:
Report link

In case people are still looking for solutions.

Rather than savings formats as xlsxwriter's Format class, I save the dictionaries first and then I instantiate them when I'm writing to cells.

This allows us to use Python's dict method to build on existing formats.

For example, I have a heading format with values centrally aligned and white background color. If I want to build on this format, let's say changing the background color to gray and using bold text then I can achieve that in the following way:

# Original format
main_header_format = {'align' : 'left', 'bg_color' : 'white'}
# Extended format
secondary_header_format = dict(main_header_format, **{'bg_color' : '#F2F2F2', 'bold' : True}

wb = writer.workbook
ws = wb.add_worksheet()

ws.write_string(1,1, 'Main header', wb.add_format(main_header_format))
ws.write_string(1, 2, 'Secondary header', wb.add_format(secondary_header_format)
Reasons:
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Bence Cserkuti