gpt4 book ai didi

grails - 在 DynamicJasper 中使用子报表

转载 作者:行者123 更新时间:2023-12-02 14:55:20 25 4
gpt4 key购买 nike

我一直在从事 Grails 的一个项目。我需要生成 pdf、excel 和 word 格式的报告。我还能够以上述格式生成报告。我使用 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
}

最佳答案

您可以从 JasperReportBuilder 创建类型对象设置要报告的属性:

JasperReportBuilder jrbSR = report();

SubreportBuilder创建一个对象:
SubreportBuilder Your_OBject= cmp.subreport(your_method(columns, your_data));

打印您的子报告:
jrb.detail(subreportTotal);

关于grails - 在 DynamicJasper 中使用子报表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6941998/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com