Java 在 ApachePOI 中使用什么代替已弃用的 CellRangeAddress.valueOf

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22267679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 14:37:19  来源:igfitidea点击:

What to use instead of deprecated CellRangeAddress.valueOf in ApachePOI

javaexcelapache-poideprecated

提问by Yoda

I wanted to add conditional formatting in the region but One method which I saw in tutorial is deprecated. What to use instead of it. Sample:

我想在该区域中添加条件格式,但我在教程中看到的一种方法已被弃用。用什么代替它。样本:

ConditionalFormattingRule rule2 = sheetCF.createConditionalFormattingRule(ComparisonOperator.LT, "50");
    PatternFormatting fill2 = rule2.createPatternFormatting();
    fill2.setFillBackgroundColor(IndexedColors.GREEN.index);
    fill2.setFillPattern(PatternFormatting.SOLID_FOREGROUND);

    CellRangeAddress[] regions = {
            CellRangeAddress.valueOf("A1:A6") //DEPRECATED
    };
    sheetCF.addConditionalFormatting(regions, rule);

回答by Gagravarr

You're using the wrong version of CellRangeAddress. org.apache.poi.hssf.util.CellRangeAddressis deprecated, the one you should be using is org.apache.poi.ss.util.CellRangeAddress.

您使用的 CellRangeAddress 版本错误。org.apache.poi.hssf.util.CellRangeAddress已弃用,您应该使用的是org.apache.poi.ss.util.CellRangeAddress

You need to use the SS Common Spreadsheet Modelclass, not the older HSSF-only one

您需要使用SS Common Spreadsheet Model类,而不是旧的 HSSF-only 类

回答by Fred Silva

Try using this:

尝试使用这个:

org.apache.poi.ss.util.CellRangeAddress.valueOf("A1:A6")