我想用JasperReports导出CSV文件。我正在使用REST,我不知道如何设置ExporterOutput。它适用于PDF / XLSX但是我无法获得CSV的解决方案。
JasperPrint jasperPrint = storageManager.generateYearAggregateXLS(id, year);
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition", "attachment;filename=Agregaty.xlsx");
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
JRCsvExporter exporter = new JRCsvExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(response.getOutputStream()));
SimpleCsvReportConfiguration configuration = new SimpleCsvReportConfiguration();
exporter.setConfiguration(configuration);
exporter.exportReport();
在exporter.setExporterOutput
我有以下问题:
The method setExporterOutput(WriterExporterOutput) in the type JRAbstractExporter<CsvReportConfiguration,CsvExporterConfiguration,WriterExporterOutput,JRCsvExporterContext> is not applicable for the arguments (SimpleOutputStreamExporterOutput)
它与excel完美配合。
答案 0 :(得分:2)
我找到了解决方案而且非常简单:
exporter.setExporterOutput(new SimpleWriterExporterOutput(response.getOutputStream()));
我已将 OutputStreamExporterOutput 中的编写器 OutputStreamExporterOutput 更改为 SimpleWriterExporterOutput