Jasper reports 如何在jasper报表中导出为excel和csv格式
我需要导出到excel和csv格式的jasper报告。 对于excel,我尝试创建自定义类(使用api),但它没有导出,问题是保存和取消弹出窗口的文件类型未知 知道为什么会发生这种情况吗?用作导出到XSL和CSV的工具 在大多数情况下,不需要创建自定义类 编辑 该类存储在jar poi-3.5-FINAL-20090928.jar中,该类应该位于“iReportInstallationFolder”\modules\ext\ 对我来说,它是Jasper reports 如何在jasper报表中导出为excel和csv格式,jasper-reports,Jasper Reports,我需要导出到excel和csv格式的jasper报告。 对于excel,我尝试创建自定义类(使用api),但它没有导出,问题是保存和取消弹出窗口的文件类型未知 知道为什么会发生这种情况吗?用作导出到XSL和CSV的工具 在大多数情况下,不需要创建自定义类 编辑 该类存储在jar poi-3.5-FINAL-20090928.jar中,该类应该位于“iReportInstallationFolder”\modules\ext\ 对我来说,它是C:\ProgramFiles\Jaspersoft\i
C:\ProgramFiles\Jaspersoft\iReport-3.7.4\iReport\modules\ext\
名称可以不同,但应为poi-3.5-FINAL-*.jar
让它包含在你的类路径中,你应该很好
您可以从主页下载jar
这里是我从他们的网站上找到的jar的链接对于那些使用JRCsvExporter的人来说,下面的代码可能很有用。给出一些示例结构 Spring框架服务类(CSVExportService.java):
请使用此代码。它工作正常@Gordon。。我得到了类似“在servlet的一个服务方法中抛出的未捕获异常:InvestorConfigServlet.exception抛出:java.lang.NoClassDefFoundError:org.apache.poi.hssf.usermodel.HSSFCellStyle”。。我将.jar文件也放在类路径中。但即使它抛出错误…您的意思是告诉报告导出到xsl吗?请编辑您的答案。通过使用JRXlsExporter,它不会导出,问题是保存和取消弹出窗口的文件类型未知。您是否尝试使用其他导出器导出您的文件?你的报告可能是空的。数据在那里。你能举个例子吗?i代码如下..reportExporter.setParameter(JRXlsExporterParameter.JASPER\u PRINT,jasperPrint);reportExporter.setParameter(JRXlsExporterParameter.OUTPUT_STREAM,reportStream);其中reportStream是“ByteArrayOutputStream()”的对象。contenttype是“response.setContentType(“application/xls”);“如果我的应用程序上没有响应(HttpServletResponse),该怎么办?如何创建文件?为什么第五行被注释?
public JasperPrint getRawData(String empIds) {
JasperPrint jp = null;
String reportName = "Employee Report";
// use your own method to get empList
// eg: List<Employee> empList = empServiceClass.findByEmpIds(empIds);
JRDataSource jrDataSource = new JRBeanCollectionDataSource(empList);
// build your report
DynamicReportBuilder dynamicReportBuilder = new DynamicReportBuilder();
dynamicReportBuilder.setAllowDetailSplit(false);
// configure your report with few more options here
// create columns
ColumnBuilder columnBuilderName = ColumnBuilder.getNew();
columnBuilderName.setTitle("Emp Name");
columnBuilderName.setWidth(300);
columnBuilderName.setFixedWidth(true);
columnBuilderName.setColumnProperty("name", String.class.getName());
dynamicReportBuilder.addColumn(columnBuilderName.build());
DynamicReport dynamicReport = dynamicReportBuilder.build();
jp = DynamicJasperHelper.generateJasperPrint(dynamicReport, new ClassicLayoutManager(), jrDataSource, new HashMap<String, Object>());
return jp;
}
public void exportToCSV(@PathVariable String empIds){
JasperPrint jp = null;
jp = csvExportService.getRawData(empIds);
response.setContentType("text/csv");
response.setHeader("Content-Disposition", "attachment; filename="EMPRawData.csv");
OutputStream out = response.getOutputStream();
JRCsvExporter exporterCSV = new JRCsvExporter();
exporterCSV.setParameter(JRExporterParameter.JASPER_PRINT, jp);
exporterCSV.setParameter(JRExporterParameter.OUTPUT_STREAM, out);
exporterCSV.exportReport();
out.flush();
}
JRCsvExporter exporter = new JRCsvExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleWriterExporterOutput(new FileOutputStream(new File(output1))));
SimpleCsvExporterConfiguration configuration = new SimpleCsvExporterConfiguration();
//configuration.setWriteBOM(Boolean.TRUE);
exporter.setConfiguration(configuration);
exporter.exportReport();