同一个excel下可以多列使用
public void setExcelComboBox(HSSFWorkbook workbook, HSSFSheet sheet, String[] data, String hiddenName, int firstRow, int lastRow, int firstCol, int lastCol) {
HSSFSheet hidden = workbook.createSheet(hiddenName);
HSSFCell cell = null;
for (int i = 0; i < data.length; i++) {
String name = data[i];
HSSFRow row = hidden.createRow(i);
cell = row.createCell(0);
cell.setCellValue(name);
}
Name namedCell = workbook.createName();
namedCell.setNameName(hiddenName);
namedCell.setRefersToFormula(hiddenName+"!$A$1:$A$" + data.length);
//加载数据,将名称为hidden的
DVConstraint constraint = DVConstraint.createFormulaListConstraint(hiddenName);
// 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列
CellRangeAddressList addressList = new CellRangeAddressList(firstRow, lastRow, firstCol, lastCol);
DataValidation validation = new HSSFDataValidation(addressList, constraint);
//将第二个sheet设置为隐藏
workbook.setSheetHidden(1, true);
sheet.addValidationData(validation);
}