我在我的servlet中設置了以下代碼,以基於字符串值的 對列進行格式化,但是在嘗試編譯時出現錯誤(org.apache.poi.ss .formula.FormulaParseException:指定的命名範圍'green'在當前工作簿中不存在)。我應該如何測試字符串值?Apache POI 3.9條件格式(字符串值)
SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();
// Condition 1: Cell Value is equal to green (Green Fill)
ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "green");
PatternFormatting fill1 = rule1.createPatternFormatting();
fill1.setFillBackgroundColor(IndexedColors.GREEN.index);
fill1.setFillPattern(PatternFormatting.SOLID_FOREGROUND);
// Condition 2: Cell Value Is equal to yellow (Yellow Fill)
ConditionalFormattingRule rule2 = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "yellow");
PatternFormatting fill2 = rule2.createPatternFormatting();
fill2.setFillBackgroundColor(IndexedColors.YELLOW.index);
fill2.setFillPattern(PatternFormatting.SOLID_FOREGROUND);
CellRangeAddress[] regions = {
CellRangeAddress.valueOf("B1:B44")
};
sheetCF.addConditionalFormatting(regions, rule1, rule2);