我正在实现下面的片段代码,以在 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:无效行号(65536)超出允许范围(0..65535)”。
我发现 saveSpreadsheetRecords 使用 HSSFSheet,其行数限制为 65535 行,并且我需要使用 XSSHSheet,但我没有找到任何线索来以某种方式使用它(ReportItemVO.class,result,outputStream) )作为输入。
请问有什么想法吗?
最佳答案
您应该实现 SpreedsheetService
而不是扩展它
@Component
public class XlsExportService implements SpreedsheetService {
}
然后您可以填写使用XSSFSheet而不是HSSFSheets的方法
关于java - 为什么java saveSpreadsheetRecords方法限制写入xls文件的行数为65535行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49260367/