日期:2014-05-16  浏览次数:20776 次

NO.88 POI升级至3.5以上后找不到org.apache.poi.hssf.util.HSSFDataValidation的问题之解决

    今天挨个检查了工程中使用的jar包,把可以升级的一律升级为第二位最高的版本,其中将poi-3.1.jar升级至poi-3.9-20121203.jar后,某个方法报org.apache.poi.hssf.util.HSSFDataValidation找不到的错误。经查阅API加瞎蒙…搞定……

 

新增代码后加了注释//add 


//import org.apache.poi.hssf.util.HSSFDataValidation;
import org.apache.poi.hssf.usermodel.DVConstraint;//add
import org.apache.poi.hssf.usermodel.HSSFDataValidation;//add
import org.apache.poi.ss.util.CellRangeAddressList;//add hssf下也有个CellRangeAddressList,但Deprecated,要用ss这个
		
String formula = "$Z$1:$Z$" + gradeList.size();// 表示Z列1-N行作为下拉列表来源数据
// HSSFDataValidation dataValidation = new HSSFDataValidation((short) 1,
// (short) 1, (short) 300, (short) 1); //原顺序为 起始行 起始列 终止行 终止列
// dataValidation.setDataValidationType(HSSFDataValidation.DATA_TYPE_LIST);
// dataValidation.setFirstFormula(formula);
// dataValidation.setSecondFormula(null);

CellRangeAddressList regions = new CellRangeAddressList((short) 1,
		(short) 300, (short) 1, (short) 1);//add  新顺序为 起始行 终止行 起始列 终止列
DVConstraint constraint = DVConstraint.createFormulaListConstraint(formula);//add
HSSFDataValidation dataValidation = new HSSFDataValidation(regions,constraint);//add
		
dataValidation.createErrorBox("Error", "Error");
dataValidation.createPromptBox("", null);