![](/img/trans.png)
[英]How can I export to PDF in JasperReports 6.1: alternate of using JRPdfExporter.setParameter method
[英]How can I export CSV with JasperReports
我想使用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)
以下问题: The method setExporterOutput(WriterExporterOutput) in the type JRAbstractExporter<CsvReportConfiguration,CsvExporterConfiguration,WriterExporterOutput,JRCsvExporterContext> is not applicable for the arguments (SimpleOutputStreamExporterOutput)
它与excel完美兼容。
我找到了解决方案,这真的很简单:
exporter.setExporterOutput(new SimpleWriterExporterOutput(response.getOutputStream()));
我已经将作家OutputStreamExporterOutput从SimpleOutputStreamExporterOutput更改为SimpleWriterExporterOutput
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.