为什么 java saveSpreadsheetRecords 方法限制在 65535 行以写入 xls 文件?
Why the java saveSpreadsheetRecords method limits in 65535 rows to write an xls file?
我正在执行下面的代码片段以在 spring 应用程序的浏览器中导出 xls 文件:
@RequestMapping(method = RequestMethod.POST, value = ResourcesPath.EXCEL,
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
@ResponseStatus(HttpStatus.OK)
public void loadExcel(ReportFilter filter, HttpServletResponse response) throws
IOException {
List<ReportItemVO> result = // list of ReportItemVO ...
Date today = new Date();
response.addHeader("Content-Disposition", "attachment; filename=today.getTime() + ".xls");
BufferedOutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
xlsExportService.saveSpreadsheetRecords(ReportItemVO.class, result, outputStream);
outputStream.flush();
outputStream.close();
}
public interface XlsExportService extends SpreadsheetService {
}
@Autowired
private XlsExportService xlsExportService;
导出 result.size() < 65535 的数据时一切正常。
否则 "java.lang.IllegalArgumentException: Invalid row number (65536) outside allowable range (0..65535)" 被抛出。
我发现 saveSpreadsheetRecords 使用限制在 65535 行的 HSSFSheet,我需要使用 XSSHSheet,但我没有找到任何线索来使用它来获得 (ReportItemVO.class , 结果, outputStream) 作为输入。
有什么想法吗?
在 XLS 的旧 Excel 格式中,最大行数为 65535:see this.
尝试以 XLSX 格式保存,最多 1,048,576 行。
您应该实施 SpreedsheetService
而不是扩展它
@Component
public class XlsExportService implements SpreedsheetService {
}
然后你可以填写使用XSSFSheet而不是HSSFSheets的方法
我正在执行下面的代码片段以在 spring 应用程序的浏览器中导出 xls 文件:
@RequestMapping(method = RequestMethod.POST, value = ResourcesPath.EXCEL,
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
@ResponseStatus(HttpStatus.OK)
public void loadExcel(ReportFilter filter, HttpServletResponse response) throws
IOException {
List<ReportItemVO> result = // list of ReportItemVO ...
Date today = new Date();
response.addHeader("Content-Disposition", "attachment; filename=today.getTime() + ".xls");
BufferedOutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
xlsExportService.saveSpreadsheetRecords(ReportItemVO.class, result, outputStream);
outputStream.flush();
outputStream.close();
}
public interface XlsExportService extends SpreadsheetService {
}
@Autowired
private XlsExportService xlsExportService;
导出 result.size() < 65535 的数据时一切正常。 否则 "java.lang.IllegalArgumentException: Invalid row number (65536) outside allowable range (0..65535)" 被抛出。
我发现 saveSpreadsheetRecords 使用限制在 65535 行的 HSSFSheet,我需要使用 XSSHSheet,但我没有找到任何线索来使用它来获得 (ReportItemVO.class , 结果, outputStream) 作为输入。
有什么想法吗?
在 XLS 的旧 Excel 格式中,最大行数为 65535:see this.
尝试以 XLSX 格式保存,最多 1,048,576 行。
您应该实施 SpreedsheetService
而不是扩展它
@Component
public class XlsExportService implements SpreedsheetService {
}
然后你可以填写使用XSSFSheet而不是HSSFSheets的方法