![](/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.