簡體   English   中英

如何使用JasperReports導出CSV

[英]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.setExporterOutputThe 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()));

我已經將作家OutputStreamExporterOutputSimpleOutputStreamExporterOutput更改為SimpleWriterExporterOutput

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM