xlsxwriter conditional formatting by formula criteria

ⅰ亾dé卋堺 提交于 2021-02-05 06:14:24

问题


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


回答1:


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".



来源:https://stackoverflow.com/questions/35338347/xlsxwriter-conditional-formatting-by-formula-criteria

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!