DynamicReports 简单使用

效果图
[img]http://dl2.iteye.com/upload/attachment/0125/3119/affb9e64-593a-35af-b023-6afddac95f36.png[/img]


public void export(@Valid PaymentChartQuery dto, HttpServletRequest request, HttpServletResponse response){
List<ColumnBuilder> colms=new ArrayList<>();

colms.add(col.reportRowNumberColumn("序号").setHorizontalTextAlignment(HorizontalTextAlignment.CENTER));
colms.add(col.column("销售单号","fsSellNo",type.stringType()));
colms.add(col.column("日期","fsSellDate",type.stringType()));
colms.add(col.column("结账时间","fsCheckEndTime",type.stringType()));
colms.add(col.column("付款金额","fdReceMoney",type.bigDecimalType()));
colms.add(col.column("付款方式","fsPaymentName",type.stringType()));
colms.add(col.column("班别","fsShiftName",type.stringType()));
colms.add(col.column("账单号","fsCheckBillNo",type.stringType()));
colms.add(col.column("收银员","fsCashier",type.stringType()));
colms.add(col.column("备注","fsNote",type.stringType()));

String filename= "付款明细表";
try {
filename = new String(filename.getBytes(), "iso8859-1");//解决中文 文件名问题
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
response.setHeader("Content-disposition", "attachment;filename="+filename+".xls");
//outstream
OutputStream outputStream = response.getOutputStream();

JasperXlsExporterBuilder xlsExporter = export.xlsExporter(outputStream).addSheetName("付款明细表")
.setDetectCellType(true).setIgnorePageMargins(true).setWhitePageBackground(false)
.setRemoveEmptySpaceBetweenColumns(true);

dto.setPrint(true);
Map<String,Object> map=paymentChartService.queryPaymentChart(dto);
List<PaymentChartDTO> list=(List)map.get(ResultCode.DATA);
List<PaymentChartTotalDTO> total= (List)map.get(ResultCode.TOTAL);
SubreportBuilder subreport1 = cmp.subreport(createTotal(total)).setFixedWidth(700);

JasperReportBuilder report=report();
report.setTemplate(Templates.reportTemplate)
.ignorePageWidth()
.title(cmp.horizontalList(subreport1),cmp.verticalGap(20))
.columns(colms.toArray(new ColumnBuilder[colms.size()]))
.setHighlightDetailEvenRows(true) //偶数行高亮显示
.highlightDetailEvenRows()
.setDataSource(list)
.toXls(xlsExporter);

outputStream.flush();
outputStream.close();
}catch (IOException e) {
e.printStackTrace();
}catch (DRException e) {
e.printStackTrace();
}
}

/**
* 合计
* @param list
* @return
*/
private JasperReportBuilder createTotal(List<PaymentChartTotalDTO> list){
JasperReportBuilder report = report();
PaymentChartTotalDTO total= list.remove(0); //总计:

List<ColumnBuilder> colms=new ArrayList<>();
TextColumnBuilder<String> fsPaymentName_col=col.column("付款方式","fsPaymentName",type.stringType()).setWidth(100);
TextColumnBuilder<BigDecimal> fdReceMoney_col=col.column("金额","fdReceMoney",type.bigDecimalType()).setWidth(100);

colms.add(col.reportRowNumberColumn("序号").setHorizontalTextAlignment(HorizontalTextAlignment.CENTER));
colms.add(fsPaymentName_col);
colms.add(fdReceMoney_col);
colms.add(col.percentageColumn("比例 %", fdReceMoney_col));

//饼图
PieChartBuilder pie_payment = cht.pieChart()
.setTitle("payment chart")
.setTitleFont(stl.fontArialBold())
.setKey(fsPaymentName_col).setShowLegend(false)
.series(cht.serie(fdReceMoney_col));

//列表
report.setTemplate(Templates.reportTemplate_2)
.columns(colms.toArray(new ColumnBuilder[colms.size()]))
.subtotalsAtSummary(sbt.text("合计:",fsPaymentName_col),sbt.sum(fdReceMoney_col))
.setDataSource(list);

SubreportBuilder subreport1 = cmp.subreport(report);

JasperReportBuilder report1=report();
report1.setTemplate(Templates.reportTemplate_2)
.summary(cmp.horizontalList(pie_payment,subreport1))
.setDataSource(list);
return report1;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值