jasperreports一次打印多张报表怎么实现
1个回答
2016-08-31
展开全部
1、若是采用bean作为数据源,可将多个条数据组装成List:
List<YourBean> list = new ArrayList<YourBean>();
list.add(xxx);
list.add(xxx);
......
2、将List装入中:
JRDataSource source =new JRBeanCollectionDataSource(list)
3、初始化jasperReport 对象:
JasperReport jasperReport = (JasperReport) JRLoader.loadObjectFromFile("你的.jasper文件路径");
4、构建JasperPrint 对象,将jasperReport 对象,source数据源填充到report中:
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,null, source);
5、获取打印机列表:
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.BYTE_ARRAY.PNG;
PrintService[] printService = PrintServiceLookup.lookupPrintServices(flavor, pras);
6、指定打印机打印:
for (PrintService p : printService) {
if("指定的打印机名称".equals(p.getName())){
JRAbstractExporter je=new JRPrintServiceExporter();
//传入jasperPrint对象
je.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint);
je.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE,p);
je.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG,false);
je.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG,false);
je.exportReport();
}
}
List<YourBean> list = new ArrayList<YourBean>();
list.add(xxx);
list.add(xxx);
......
2、将List装入中:
JRDataSource source =new JRBeanCollectionDataSource(list)
3、初始化jasperReport 对象:
JasperReport jasperReport = (JasperReport) JRLoader.loadObjectFromFile("你的.jasper文件路径");
4、构建JasperPrint 对象,将jasperReport 对象,source数据源填充到report中:
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,null, source);
5、获取打印机列表:
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.BYTE_ARRAY.PNG;
PrintService[] printService = PrintServiceLookup.lookupPrintServices(flavor, pras);
6、指定打印机打印:
for (PrintService p : printService) {
if("指定的打印机名称".equals(p.getName())){
JRAbstractExporter je=new JRPrintServiceExporter();
//传入jasperPrint对象
je.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint);
je.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE,p);
je.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG,false);
je.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG,false);
je.exportReport();
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询