JavaEar 专注于收集分享传播有价值的技术资料

在ApachePOI中使用什么而不是弃用的CellRangeAddress.valueOf (What to use instead of deprecated CellRangeAddress.valueOf in ApachePOI)

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

2个回答

    最佳答案

  1. 英文原文

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

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


    中文翻译

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

    您需要使用 SS通用电子表格模型类,而不是旧版的HSSF

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

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

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

    您需要使用 SS通用电子表格模型类,而不是旧版的HSSF

  2. 参考答案2
  3. Try using this:

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