欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

Java报表解决方案By Birt,java报表bybirt,package repo

来源: javaer 分享于  点击 43688 次 点评:191

Java报表解决方案By Birt,java报表bybirt,package repo


package report;import java.util.Map;import java.util.logging.Level;import org.eclipse.birt.core.exception.BirtException;import org.eclipse.birt.core.framework.Platform;import org.eclipse.birt.report.engine.api.EXCELRenderOption;import org.eclipse.birt.report.engine.api.EngineConfig;import org.eclipse.birt.report.engine.api.EngineException;import org.eclipse.birt.report.engine.api.HTMLRenderOption;import org.eclipse.birt.report.engine.api.IReportEngine;import org.eclipse.birt.report.engine.api.IReportEngineFactory;import org.eclipse.birt.report.engine.api.IReportRunnable;import org.eclipse.birt.report.engine.api.IRunAndRenderTask;public class ReportProcess {    //报表路径    private static final String REPORT_HOME_PATH = "D:/Java/eclipse/workspace/TestBirt/";    //报表引擎环境路径    private static final String REPORT_ENGINE_HOME_PATH = "E:/TDDOWNLOAD/birt-runtime-2_6_1/birt-runtime-2_6_1/ReportEngine";    public static void execReport(String report,Map<String,String> paramMap,String format,String outPath) throws EngineException {        IReportEngine engine = null;        IRunAndRenderTask task = null;        IReportRunnable design = null;        try {            EngineConfig config = new EngineConfig();            config.setEngineHome(REPORT_ENGINE_HOME_PATH);            config.setLogConfig("d:/birt/logs", Level.FINE);            Platform.startup(config);            IReportEngineFactory factory = (IReportEngineFactory) Platform                    .createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);            engine = factory.createReportEngine(config);            design = engine.openReportDesign(REPORT_HOME_PATH + report);        } catch (BirtException e) {            e.printStackTrace();        }        task = engine.createRunAndRenderTask(design);        if(paramMap != null){            task.setParameterValues(paramMap);            task.validateParameters();        }        if(format.equalsIgnoreCase("xls")){            EXCELRenderOption optionsWithXLS = new EXCELRenderOption();             optionsWithXLS.setOutputFormat(format);            optionsWithXLS.setOutputFileName(outPath);            task.setRenderOption(optionsWithXLS);        }        if(format.equalsIgnoreCase("html")){            HTMLRenderOption options = new HTMLRenderOption();            options.setOutputFormat(format);            options.setOutputFileName(outPath);            task.setRenderOption(options);        }        task.run();        task.close();        engine.shutdown();        Platform.shutdown();    }}//该片段来自于http://byrx.net
相关栏目:

用户点评