大哥,问下:我要在ireport中打印2个报表,分别在2个sheet中,怎么实现?看你回答别人的,没看懂,教下谢

 我来答
yhy3734
2012-09-17 · TA获得超过3969个赞
知道小有建树答主
回答量:909
采纳率:0%
帮助的人:446万
展开全部
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页的话几个数组参数里就封装两个相应对象就可以了,你打印一个的时候数据是什么样的,再弄一个类似的,封装到一起就行了
来自:求助得到的回答
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式