C # Excel export exceeded (65536) outside allowable range 65536 line error Invalid row number (0..65535)

  C # Excel export exceeded (65536) outside allowable range 65536 line error Invalid row number (0..65535)

A: error

Invalid row number (65536) outside allowable range (0..65535)

The reason: excel 03-line limit is 65536, exceeding the number of rows on the error

Two: Solutions - Create multiple 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) - (65535 * index));
// fourth step, creating a cell, and sets the value
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;

}
----------------
Disclaimer: This article is CSDN blogger "m0_37934074 'original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source and this link statement.
Original link: https: //blog.csdn.net/m0_37934074/article/details/79409292

Guess you like

Origin www.cnblogs.com/woniucode/p/12167942.html