mil*_*s55 2 conditional-formatting apache-poi
我在 servlet 中设置了以下代码,以根据字符串值格式化列,但是在尝试编译时出现错误(org.apache.poi.ss.formula.FormulaParseException:指定的命名范围“绿色”不存在于当前工作簿中。)。我应该如何测试字符串值?
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);
Run Code Online (Sandbox Code Playgroud)
小智 5
我遇到了这个问题,并通过在字符串上添加双引号来解决它,以便“green”变成“\”green\“”。
ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "\"green\"");
希望它有效。
| 归档时间: |
|
| 查看次数: |
3743 次 |
| 最近记录: |