Xlswriter formatting range

In xlswriter, once the format is defined, how can you apply it to a range and not to the entire column or entire row?

eg:

perc_fmt = workbook.add_format({'num_format': '0.00%','align': 'center'})
worksheet.set_column('B:B', 10.00, perc_fmt)

this applies to the entire column "B", but how this "perc_fmt" applies to the range, for example, if I do this:

range2 = "B2:C15"
worksheet2.write(range2, perc_fmt)

He says:

TypeError: Unsupported type <class 'xlsxwriter.format.Format'> in write()
+4
source share
2 answers

Actually, I found a workaround that avoids the loop. You just need to use conditional formatting (which takes a range as input) and just format all cases. For example:

worksheet2.conditional_format(color_range2, {'type': 'cell',
                                     'criteria': '>=',
                                     'value': 0, 'format': perc_fmt})
worksheet2.conditional_format(color_range2, {'type': 'cell',
                                     'criteria': '<',
                                     'value': 0, 'format': perc_fmt})  
+2
source

In xlswriter, once the format is defined, how can you apply it to a range and not to the entire column or entire row?

. .

+1

Source: https://habr.com/ru/post/1618148/


All Articles