
poi下拉列表项过多
在使用poi设置excel下拉列表时,如果下拉项过多,下载模板后可能无法正确显示。这是因为poi默认使用内存的数据结构来存储下拉项,当选项过多时,内存消耗过大,会出现性能问题。
解决方案
为了解决此问题,可以创建另一个作为引用页的sheet,并使用公式来引用该sheet中的下拉项列表。这种方法可以减少内存消耗,使大量下拉项也能正常展示。
// 创建引用页
XSSFSheet refSheet = workbook.createSheet("refSheet");
// 将下拉项列表添加到引用页
for (int i = 0; i zuojiankuohaophpcn departList.length; i++) {
XSSFRow row = refSheet.createRow(i);
XSSFCell cell = row.createCell(0);
cell.setCellValue(departList[i]);
}
// 使用公式引用引用页的列表
String formula = "refSheet!$A$1:$A$" + departList.length;
DataValidationConstraint constraint = helper.createFormulaListConstraint(formula);
// ...其余设置相同










