Select column for formatting based on cell content

Viewed 40

In xlsxWriter I can format a column by selecting its column index as it is in Excel via letters e.g. worksheet.set_column('V:V', 20, cell_format). Is it also possible to define which column to format based on its value (e.g. header columns)?

For example worksheet.set_column('cell_value', 20, cell_format)?

1 Answers

Is it also possible to define which column to format based on its value (e.g. header columns)?

That isn't possible using xlsxwriter, which in general is a write-only data store. Instead you could track the column headers and indices in a dict and use that. Something like

cols = {'Year' : 0, 'Income': 1, 'Outgoings': 2}


worksheet.set_column(cols['Year'], cols['Year'], 20, cell_format)

Related