C# Excel导出超出65536行报错 Invalid row number (65536) outside allowable range (0..65535)
一:报错
Invalid row number (65536) outside allowable range (0..65535)
原因:excel 03的限制就是65536行,超过行数就报错
二:解决方案-创建多个sheet
public String export(List<Record> list, String f) {
String name = "";
HSSFWorkbook book = new HSSFWorkbook();
HSSFSheet sheet = book.createSheet("stud");
// 声明一行
HSSFRow row = sheet.createRow(0);
row = sheet.createRow(0);
row.createCell(0).setCellValue("身份");
row.createCell(1).setCellValue("信用");
int index = 0;//记录额外创建的sheet数量
for (int i = 0; i < list.size(); i++) {
if ((i + 1) % 65535 == 0) {
sheet = book.createSheet("stud" + index);
row = sheet.createRow(0);
row.createCell(0).setCellValue("身份");
row.createCell(1).setCellValue("信用");
index++;
}
row = sheet.createRow((i + 1) - (index * 65535));
// 第四步,创建单元格,并设置值
row.createCell((short) 0).setCellValue(list.get(i).getStr("info"));
row.createCell((short) 1).setCellValue(list.get(i).getStr("score"));
}
// 第六步,将文件存到指定位置
String fileName = "";
try {
fileName = f + "/download/导出.xls";
name = "导出.xls";
File file = new File(fileName);
if (file.exists()) {
file.delete();
}
FileOutputStream fout = new FileOutputStream(fileName);
book.write(fout);
fout.close();
} catch (Exception e) {
e.printStackTrace();
}
return name;
}
————————————————
版权声明:本文为CSDN博主「m0_37934074」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/m0_37934074/article/details/79409292
C# Excel导出超出65536行报错 Invalid row number (65536) outside allowable range (0..65535)