gpt4 book ai didi

apache-poi - Apache POI 3.9 条件格式(字符串值)

转载 作者:行者123 更新时间:2023-12-02 15:36:31 26 4
gpt4 key购买 nike

我在我的 servlet 中设置了以下代码来格式化基于列的格式在字符串值上但是,我在尝试编译时遇到错误(org.apache.poi.ss.formula.FormulaParseException:当前工作簿中不存在指定的命名范围'green'。)。我应该如何测试字符串值?

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);

最佳答案

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

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

希望它有用。

关于apache-poi - Apache POI 3.9 条件格式(字符串值),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16650763/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com