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

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

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

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

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

尝试使用这个:

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