码迷,mamicode.com
首页 > 其他好文 > 详细

ireport 追加新报表

时间:2014-11-20 15:03:38      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:cPage   style   blog   io   ar   color   os   sp   java   

ireport  追加新报表

/* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRPrintPage;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;

/**
*
* @authored by vijayan.A
* @reviewed by Krishnaveni.T
*/
public class MultiPageLinking {

private Map fillReportParameters() {
Map parametersMap = new HashMap();
Map reportparametermap1 = new HashMap();
Map reportparametermap2 = new HashMap();
Map reportparametermap3 = new HashMap();

reportparametermap1.put("Parameter1", "First Name");
reportparametermap1.put("Parameter2", "Middle Name");
reportparametermap1.put("Parameter3", "Last Name");

reportparametermap2.put("Parameter21", "Address1");
reportparametermap2.put("Parameter22", "Address2");
reportparametermap2.put("Parameter23", "Address3");

reportparametermap3.put("Parameter31", "Phone no");
reportparametermap3.put("Parameter32", "Mobile no");
reportparametermap3.put("Parameter33", "Fax no");

parametersMap.put("reportparametermap1", reportparametermap1);
parametersMap.put("reportparametermap2", reportparametermap2);
parametersMap.put("reportparametermap3", reportparametermap3);

return parametersMap;
}

private JasperPrint fillJasperPrint(String jasperpath, Map parametersMap) 
throws IOException, JRException {
JasperPrint jasperprint = new JasperPrint();
jasperprint = JasperFillManager.fillReport(getClass().
getResource(jasperpath).openStream(), parametersMap);
return jasperprint;
}

private JasperPrint getLinkedStaticpages() throws IOException, JRException {
Map page1param, page2param, page3param;
page1param = (Map) fillReportParameters().get("reportparametermap1");
page2param = (Map) fillReportParameters().get("reportparametermap2");
page3param = (Map) fillReportParameters().get("reportparametermap3");

JasperPrint firstsecondlinked = multipageLinking(fillJasperPrint("com/page1 .jasper", page1param), fillJasperPrint("com/page2.jasper", page2param));
JasperPrint firstsecondthirdlinked = multipageLinking(firstsecondlinked, fillJasperPrint("com/page3.jasper", page3param));
return firstsecondthirdlinked;
}

private JasperPrint multipageLinking(JasperPrint page1, JasperPrint page2) {
List pages = page2.getPages();
for (int count = 0; count <
pages.size(); count++) {
page1.addPage(pages.get(count));
}

return page1;
}

private void viewer(JasperPrint page1) {
JasperViewer viewer = new JasperViewer(page1, false);
viewer.setVisible(true);
}

public static void main(String arg[]) throws IOException, JRException {
MultiPageLinking multipages = new MultiPageLinking();
JasperPrint allpages = multipages.getLinkedStaticpages();
multipages.viewer(allpages);
}
}

 

ireport 追加新报表

标签:cPage   style   blog   io   ar   color   os   sp   java   

原文地址:http://www.cnblogs.com/rojas/p/4110515.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!