如何使用jsp显示excel,避免“没有输入源提供给导出器”。
我已经写了一些代码来在网站上显示excel。
但我得到了这个例外
net.sf.jasperreports.engine.JRRuntimeException:没有提供给导出器的输入源。
我的代码
在jsp中导入
jsp代码导出到excel
怎么解决这个问题?
如果您没有使用旧版本的JasperReports,那么您使用的是弃用的方法,最重要的是您没有将JasperPrint
传递给导出器。
没有输入源提供给导出器。
您需要使用JasperFillManager.fillReport
填充报告
示例代码(jasper report v5或更高版本)
JasperDesign jasperDesign = JRXmlLoader.load(new FileInputStream(reportFile)); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperDesign, parameters, conn); JRXlsExporter exporter = new JRXlsExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); //The JasperPrint, filled report exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(xlsReport)); //Your ByteArrayOutputStream SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration(); configuration.setOnePagePerSheet(true); configuration.setDetectCellType(true); configuration.set //The other properties you like to set exporter.setConfiguration(configuration); exporter.exportReport();