当我使用Apache POI - 使用以下方法命名Cell时创建excel下拉列表时,我遇到了一个奇怪的问题。
public static void createHugeDropDown(XSSFWorkbook wb) {
int i = 0;
String sheetName = "LOOKUP";
String colName = "COL1";
String mainSheet = "sheet1";
String[] strArray = new String[]{"10", "20", "30"};
XSSFSheet sheet = wb.createSheet(sheetName);
for (String str : strArray) {
sheet.createRow(i++).createCell(0).setCellValue(str);
}
XSSFName namedCell = wb.createName();
namedCell.setNameName(colName);
String reference = sheetName + "!A1:A" + i;
System.out.println(reference);
namedCell.setRefersToFormula(reference);
XSSFSheet sheet1 = wb.getSheet(mainSheet);
int namedCellIndex = wb.getNameIndex(colName);
namedCell = wb.getNameAt(namedCellIndex);
AreaReference aref = new AreaReference(namedCell.getRefersToFormula());
CellReference[] crefs = aref.getAllReferencedCells();
System.out.println("Total Count --> " + crefs.length);
for (int count = 0; count < crefs.length; count++) {
Sheet s = wb.getSheet(crefs[count].getSheetName());
Row r = sheet.getRow(crefs[count].getRow());
Cell c = r.getCell(crefs[count].getCol());
System.out.println("Cell Value" + c.getStringCellValue());
}
DataValidationConstraint constraint = null;
DataValidation dataValidation = null;
CellRangeAddressList addressList = new CellRangeAddressList(0, 100, 2, 2);
DataValidationHelper validationHelper = new XSSFDataValidationHelper(sheet1);
System.out.println(reference);
constraint = validationHelper.createFormulaListConstraint(reference);
dataValidation = validationHelper.createValidation(constraint, addressList);
dataValidation.setSuppressDropDownArrow(true);
wb.getSheet(mainSheet).addValidationData(dataValidation);
}
这会让我感到沮丧。但问题是 1)我有10,20&amp;第一排30 2)有20&amp;单独在第二排30 3)第三排有30个人。 4)从第四排到第100排空下降。
有人可以在上面的代码中指出我的问题。
我想在所有行的下拉列表中显示所有3个值。