我正在使用JasperReports生成一个报告,并假设将其导出为多种格式.但目前我只使用excel报告.
这是我的控制器代码.
InputStream in = reportTemplate.getTemplate(reportInquery.getTemplateFile());
JasperPrint print = JasperFillManager.fillReport(in, null,
new JRResultSetDataSource(reportDao.getReportData(reportInquery)));
resp = HttpConfig.setHeaders(reportInquery, resp);
Exporter exporter = reportOption.getRenderOptions(reportInquery.getFormat(), resp.getOutputStream(), print);
exporter.exportReport();
Run Code Online (Sandbox Code Playgroud)
在我的配置工厂中,excel报告在调用getRenderOptions方法后配置如下.
public Exporter exporterOptions(OutputStream outputStream, JasperPrint print) {
JRXlsExporter exporter = new JRXlsExporter();
exporter.setExporterInput(new SimpleExporterInput(print));
OutputStreamExporterOutput outputStreamExporterOutput = new SimpleOutputStreamExporterOutput(outputStream);
exporter.setExporterOutput(outputStreamExporterOutput);
SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration();
configuration.setOnePagePerSheet(true);
configuration.setDetectCellType(true);
configuration.setMaxRowsPerSheet(100);
configuration.setRemoveEmptySpaceBetweenColumns(true);
configuration.setRemoveEmptySpaceBetweenRows(true);
exporter.setConfiguration(configuration);
return exporter;
}
Run Code Online (Sandbox Code Playgroud)
创建JRResultSetDataSource我OracleCachedRowSet在上面的getReportData方法中使用了oracle .
public RowSet getReportData(ReportInqueryDTO reportInquery) {
try {
String query …Run Code Online (Sandbox Code Playgroud)