1
我一直在Grails項目中工作。我需要用pdf,excel和word生成報告。我還能夠以上述格式生成報告。我已經使用DynamicJasper來生成報告。在DynamicJasper中使用子報表
現在我需要在生成的報告中的子報告。
生成的報告包含以下表餅圖沿,現在我需要像在這同表所示無1 子報告:
表沒有1
SN | Top 20 |Reporting |Comparison
1 | Dorsopathies |$181 |$5
2 | Special |$23 |$6
3 | Other Wounds |$20 |$0
報告期間
Members| M Cost |P Cost
47 | $4,995,541 |$1,598,049
234 | $2,576,497 |$824,209
我的代碼生成的報告是這樣的:
if (params.format) {
String svg = params.svg
def imagePath = fetchService.getChartImage(svg)
FastReportBuilder drb = new FastReportBuilder();
if (imagePath && imagePath!='') {
drb.setTemplateFile(root+"/reports/template_chart.jrxml")
} else {
drb.setTemplateFile(root+"/reports/template.jrxml")
}
Style changeStyle = new Style()
changeStyle.setHorizontalAlign(HorizontalAlign.CENTER)
DynamicReport dr = drb.addColumn("S.N", "S.N",Integer.class.getName(),30, changeStyle).
addColumn("Top 20", "Top 20 ",String.class.getName(),150).
addColumn("Reporting ","Reporting ",Double.class.getName(), 50, false, '$0.00').
addColumn("Comparison ","Comparison ",Double.class.getName(), 50, false, '$0.00').
addColumn("Prior Period Ranking","Prior Period Ranking",String.class.getName(), 50, changeStyle).
setTitle(" ").
setUseFullPageWidth(true).
build();
JRDataSource ds = new JRBeanCollectionDataSource(data);
JasperPrint jp = DynamicJasperHelper.generateJasperPrint(dr,new ClassicLayoutManager(), ds);
HashMap reportParam = new HashMap();
reportParam.put("TITLE","Top 20 ");
reportParam.put("IMAGE_LINK",root+"/images/report_logo.jpg");
reportParam.put("CHART_IMAGE",imagePath);
generateReport(params.format, jp)
fetchService.deleteTempFile(imagePath)
return
}
[data: data, columns: columns , totalRep : totalRep, totalCom:totalCom, currentPage:'']
}
def generateReport(String format, JasperPrint jp){
ReportWriter reportWriter
switch (format) {
case "word":
JRDocxExporter docExporter = new JRDocxExporter();
ByteArrayOutputStream docStream = new ByteArrayOutputStream();
docExporter.setParameter(JRDocxExporterParameter.JASPER_PRINT,jp);
docExporter.setParameter(JRDocxExporterParameter.OUTPUT_STREAM,docStream);
docExporter.setParameter(JRDocxExporterParameter.FLEXIBLE_ROW_HEIGHT, Boolean.TRUE);
docExporter.exportReport();
def docResume = docStream.toByteArray();
response.setHeader("Content-disposition", "attachment; filename=\"" + "Report" + ".docx\"");
response.outputStream << docResume
case "excel":
reportWriter = ReportWriterFactory.getInstance().getReportWriter(jp, 'XLS', [:]);
response.setHeader("Content-disposition", "attachment; filename=\"" + "Report" + ".xls\"");
break
default:
reportWriter = ReportWriterFactory.getInstance().getReportWriter(jp, 'PDF', [:]);
response.setHeader("Content-disposition", "attachment; filename=\"" + "Report" + ".pdf\"");
break
}
reportWriter?.writeTo(response);
return
}