poi之getPhysicalNumberOfCells与getLastCellNum

某次调用row.getPhysicalNumberOfCells来循环标题,给某些列设置下拉列表(超过255字符,引用其他sheet页面)。

一直以为是设置下拉列表的方式有问题,但是找了很多资料是没有问题的。最后发现同样的设置方法有些列设置成功了,就是最后一列设置不成功。

打印日志,果然发现没有获取最后一列。

然后网上找getPhysicalNumberOfCells的使用,发现次方法不统计空列,但我的标题第一行是空的。然后换getLastCellNum解决问题





附:
超过255字符的下拉列表设置,引用隐藏的sheet的列
Sheet sheetHid = wb.createSheet("hidden");
wb.setSheetHidden(wb.getSheetIndex("hidden"), true);

Cell cellHid = null;
        for (int h = 0, length= dataList.length; h < length; h++) {
           String name = dataList[h];
           Row rowHid = sheetHid.createRow(h);
           cellHid = rowHid.createCell(0);
           cellHid.setCellValue(name);
        }
Name namedCell = wb.createName();
namedCell.setNameName("data");
namedCell.setRefersToFormula("hidden!$A$1:$A$" + dataList.length);
            DVConstraint constraintData = DVConstraint.createFormulaListConstraint("data");




CellRangeAddressList regions = new CellRangeAddressList(1, rowIdx - 1, i, i);
            HSSFDataValidation dataValidation = new HSSFDataValidation(regions, constraintData);
            sheet.addValidationData(dataValidation);


参考:
http://wing123.iteye.com/blog/1936924

猜你喜欢

转载自newjava-sina-cn.iteye.com/blog/2405002
poi
今日推荐