【问题标题】:Apache POI 3.9 conditional formatting (string value)Apache POI 3.9 条件格式(字符串值)
【发布时间】:2013-05-20 13:36:18
【问题描述】:

我在我的 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);

【问题讨论】:

    标签: apache-poi conditional-formatting


    【解决方案1】:

    我遇到了这个问题,并通过在字符串上添加双引号来解决它,这样“green”就变成了“\”green\””。

    ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "\"green\"");

    希望它有效。

    【讨论】:

      【解决方案2】:

      使用更新的...当您单独应用这两个规则时它会起作用

       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);
      CellRangeAddress[] regions = {CellRangeAddress.valueOf("B1:B44")};
      sheetCF.addConditionalFormatting(regions, rule1);
      
      // 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);
      sheetCF.addConditionalFormatting(regions, rule2);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-10-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-07
        • 1970-01-01
        • 1970-01-01
        • 2021-02-28
        相关资源
        最近更新 更多