怎样实现JasperReport循环打印 or 多表打印
1个回答
展开全部
我用的是FineReport,比较方便,jasperreport不太了解。下面是百度的答案,希望对你有帮助。
批量导出思路如皮嫌下:
1、数据库里面取出数据
2、调用项目工具类中生成报表打印数据的方法(每张表数据都要放到一个list集合中)
java 代码
String path = this.getClass().getResource("/").getPath();
path = path.substring(1,path.lastIndexOf("classes"));
String fileName = path+"jasperreport"+"\"+reportFileName+".jasper";
System.out.println("_________ FileName:"+fileName);
//装载jasper文件application
File reportFile = new File(fileName);
Map map = new HashMap();
JasperReport jasperReport = null;
DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String s = format1.format(new Date());
/燃贺手/取得JasperPrint 的集合
for (Object e : list) {
List<Evaluate> tempList = new ArrayList<Evaluate>();
tempList.add((Evaluate)e);
jasperPrint = JasperFillManager.fillReport(reportFile.getPath(),null,
new JRBeanCollectionDataSource(tempList));
list2.add(jasperPrint);
}
//生成报表数据并填入OutputStream
JRPdfExporter exporter=new JRPdfExporter ();
ServletOutputStream output = null;
try {
output = getResponse().getOutputStream();
getResponse().setHeader("Content-disposition","attachment; filename="+exportFileName+s+".pdf");//exportFileName导出文件名字 s 表示年月日时分秒
exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, list2);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,output);
/拍弊/ exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, list);
exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8");
exporter.exportReport();
} catch (Exception e) {
e.printStackTrace();
}
批量导出思路如皮嫌下:
1、数据库里面取出数据
2、调用项目工具类中生成报表打印数据的方法(每张表数据都要放到一个list集合中)
java 代码
String path = this.getClass().getResource("/").getPath();
path = path.substring(1,path.lastIndexOf("classes"));
String fileName = path+"jasperreport"+"\"+reportFileName+".jasper";
System.out.println("_________ FileName:"+fileName);
//装载jasper文件application
File reportFile = new File(fileName);
Map map = new HashMap();
JasperReport jasperReport = null;
DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String s = format1.format(new Date());
/燃贺手/取得JasperPrint 的集合
for (Object e : list) {
List<Evaluate> tempList = new ArrayList<Evaluate>();
tempList.add((Evaluate)e);
jasperPrint = JasperFillManager.fillReport(reportFile.getPath(),null,
new JRBeanCollectionDataSource(tempList));
list2.add(jasperPrint);
}
//生成报表数据并填入OutputStream
JRPdfExporter exporter=new JRPdfExporter ();
ServletOutputStream output = null;
try {
output = getResponse().getOutputStream();
getResponse().setHeader("Content-disposition","attachment; filename="+exportFileName+s+".pdf");//exportFileName导出文件名字 s 表示年月日时分秒
exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, list2);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,output);
/拍弊/ exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, list);
exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8");
exporter.exportReport();
} catch (Exception e) {
e.printStackTrace();
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询