我正在尝试格式化5以下的黄色背景的单元格,并且此范围内的所有空白单元格也会突出显示。尝试与null“”和“\”\“”相等的规则似乎没有工作。apache poi条件格式化空白单元格
已经通过将GT 5设置为第二条规则进行了测试,并将红色设置为可以正常工作的颜色。
空白字段条件格式是可以在Excel中完成的事情,并且我还没有设法找到任何与使用apache-poi实现相同目的相关的任何内容。
好奇,如果任何人已设法使其工作(这是常规所以地区可能会有所不同)
SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting()
ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule(ComparisonOperator.LT, "5")
PatternFormatting fill1 = rule1.createPatternFormatting()
fill1.setFillBackgroundColor(IndexedColors.YELLOW.index)
fill1.setFillPattern(PatternFormatting.SOLID_FOREGROUND)
//try and set the fields that are blank back to white cells - is not working from below unsure if it will work
//https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/SheetConditionalFormatting.html
ConditionalFormattingRule rule2 = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL,"\"\"")
PatternFormatting fill2 = rule2.createPatternFormatting()
fill2.setFillBackgroundColor(IndexedColors.WHITE.index)
fill2.setFillPattern(PatternFormatting.SOLID_FOREGROUND)
CellRangeAddress[] regions = [ CellRangeAddress.valueOf("M11:T${counter}") ].toArray()
我没有看到''M11:T $ {counter}“'应该选择什么范围。 –
有关空白单元格的POI有时会有点奇怪。您是否调试过您的代码以验证_cell本身_不为null? – Frank
@Nicholas范围在这个例子中并不重要,可能M11:T18。该计数器是由于动态内容。 – Vahid