java - 为什么java saveSpreadsheetRecords方法限制写入xls文件的行数为65535行?

标签 java spring xls

我正在实现下面的片段代码,以在 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/

相关文章:

java - 导入 com.sun.org.apache.xpath.internal.operations 时出现问题

java - 注入(inject)静态字段 Kotlin/Spring Boot

python - 通读非结构化 xls 文件

java - 在 Java 中将 .csv 转换为 .xls

c# - 使用 C# 读取基于 HTML 的 XLS 时出现问题

java - 为按钮添加事件

java - 需要解释以下java代码的输出

java - java中如何让对象相互交互?

java - Spring bean中如何释放资源?

spring - Apache Camel Spring 配置错误 - 无法找到 XML 模式命名空间的 Spring NamespaceHandler [http ://camel. apache.org/schema/spring]