What to use instead of deprecated CellRangeAddress.valueOf in ApachePOI

浪子不回头ぞ 提交于 2021-02-08 12:46:34

问题


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

回答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




回答2:


Try using this:

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


来源:https://stackoverflow.com/questions/22267679/what-to-use-instead-of-deprecated-cellrangeaddress-valueof-in-apachepoi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!