简体   繁体   中英

xlsxwriter conditional formatting by formula criteria

I want to apply format to cells in a column. The row indexes are 5,7,8,9,10,11 and 13.

The code I am using is the following:

 worksheet.conditional_format("C4:C14", {'type'    :  'formula',
                                           'criteria': '=ISNUMBER(MATCH(ROW(),{5,7,8,9,10,11,13},0))=TRUE',
                                           'format'  :   format_white})

The result is no Excel file is generated.

The formula =ISNUMBER(MATCH(ROW(),{5,7,8,9,10,11,13},0))=TRUE works as I expected when I type it directly in Excel. I run the code above with a simpler formula 'criteria': '=MOD(ROW(),2)=0' and it works, so I suspect the problem is in the criteria field.

Can anyone help me? Thanks in advance

In order for a formula to work in an XlsxWriter generated file it has to work in Excel.

In this case the conditional formula formula isn't valid in Excel:

=ISNUMBER(MATCH(ROW(),{5,7,8,9,10,11,13},0))=TRUE

If you add it manually in Excel you get the following error/warning:

"You may not use reference operators (such as unions, intersections, and ranges) or other array constants for Conditional Formatting criteria".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM