
大哥,问下:我要在ireport中打印2个报表,分别在2个sheet中,怎么实现?看你回答别人的,没看懂,教下谢
1个回答
展开全部
public void getPrintConcatenationPdfList(Object[] reportFilePath,
Object[] objlist, Object[] maplist,HttpServletResponse response) throws Exception, BusinessException {
// TODO Auto-generated method stub
System.out.println("生成PDF开始:"+new Date());
try{
List jasperPrintList = new ArrayList();
if(reportFilePath!=null){
if(objlist!=null){
int length = reportFilePath.length;
for(int i=0;i<length;i++){
String path = reportFilePath[i].toString();//模板地址
List templist = (List)objlist[i];
Map map = (Map)maplist[i];
JRDataSource dataSource = new JRBeanCollectionDataSource(templist);
JasperPrint jasperPrint = JasperFillManager.fillReport(path, map, dataSource);
jasperPrintList.add(jasperPrint);
}
}
}
//获取输出字节流
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST,
jasperPrintList);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
exporter.exportReport();
byte[] bytes = baos.toByteArray();
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();
System.out.println("生成PDF结束:"+new Date());
}catch(Exception e){
e.printStackTrace();
}
}
这个方法就可以直接用就行了,两个sheet页的话几个数组参数里就封装两个相应对象就可以了,你打印一个的时候数据是什么样的,再弄一个类似的,封装到一起就行了
Object[] objlist, Object[] maplist,HttpServletResponse response) throws Exception, BusinessException {
// TODO Auto-generated method stub
System.out.println("生成PDF开始:"+new Date());
try{
List jasperPrintList = new ArrayList();
if(reportFilePath!=null){
if(objlist!=null){
int length = reportFilePath.length;
for(int i=0;i<length;i++){
String path = reportFilePath[i].toString();//模板地址
List templist = (List)objlist[i];
Map map = (Map)maplist[i];
JRDataSource dataSource = new JRBeanCollectionDataSource(templist);
JasperPrint jasperPrint = JasperFillManager.fillReport(path, map, dataSource);
jasperPrintList.add(jasperPrint);
}
}
}
//获取输出字节流
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST,
jasperPrintList);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
exporter.exportReport();
byte[] bytes = baos.toByteArray();
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();
System.out.println("生成PDF结束:"+new Date());
}catch(Exception e){
e.printStackTrace();
}
}
这个方法就可以直接用就行了,两个sheet页的话几个数组参数里就封装两个相应对象就可以了,你打印一个的时候数据是什么样的,再弄一个类似的,封装到一起就行了
来自:求助得到的回答
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询