ireport 追加新报表
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); } }