如果您下載3.7運行時,您應該能夠構建一個命令 運行報告的線路應用程序。附上一個簡單的例子。要建立 這個類,請確保在類路徑中有運行時的 download/reportengine/lib目錄中的jar。一旦建成,您應該可以像調用簡單的Java應用程序一樣調用該應用程序 。如果您要生成大量報告,此 示例會執行平臺啓動和關閉,這通常不是 的好主意。更好的 解決方案是將平臺啓動和報表引擎創建包裝在一個 單例中,該單例在服務器啓動時啓動,然後使用引擎爲 創建每個請求的新任務。
import java.util.logging.Level;
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.EngineConstants;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.HTMLServerImageHandler;
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;
import org.eclipse.birt.report.engine.api.PDFRenderOption;
import org.eclipse.birt.report.engine.api.RenderOption;
import org.eclipse.birt.report.engine.api.impl.RunAndRenderTask;
import org.eclipse.birt.report.engine.api.script.IReportContext;
public class RunAndRenderTaskTest {
public void runReport() throws EngineException
{
RunAndRenderTask task=null;
IReportEngine engine=null;
EngineConfig config = null;
try{
config = new EngineConfig();
//config.setLogConfig("c:/dwn", Level.SEVERE);
//config.setResourcePath("C:/work/workspaces/3.7.1workspaces/BIRT
Metal/APIs/resources");
Platform.startup(config);
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject(
IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
engine = factory.createReportEngine(config);
IReportRunnable design = null;
//Open the report design
design = engine.openReportDesign("Reports/testlibrary.rptdesign");
task = (RunAndRenderTask) engine.createRunAndRenderTask(design);
IReportContext irc = task.getReportContext();
//task.setParameterValue("Top Count", (new Integer(5)));
//task.validateParameters();
//HTMLRenderOption options = new HTMLRenderOption();
//options.setImageDirectory("./");
//options.setOutputFileName("output/resample/external.html");
//options.setOutputFormat("html");
//options.setEmbeddable(false);
//options.setEnableMetadata(true);
//options.setEnableInlineStyle(false);
//options.setEnableAgentStyleEngine(true);
//options.setEnableCompactMode(true);
//PDFRenderOption options = new PDFRenderOption();
//options.setOutputFileName("output/resample/hidefooter.pdf");
//options.setSupportedImageFormats("PNG;GIF;JPG;BMP;SWF;SVG");
//options.setOutputFormat("pdf");
//EXCELRenderOption options = new EXCELRenderOption();
//options.setOutputFormat("xls");
//options.setOutputFileName("output/resample/customers.xls");
//options.setWrappingText(true);
HTMLRenderOption options = new HTMLRenderOption();
//options.setImageHandler(new HTMLServerImageHandler());
options.setSupportedImageFormats("JPG;PNG;BMP;SVG;GIF");
options.setOutputFileName("output/resample/testlibrary.html");
options.setOutputFormat("html");
//options.setOutputFormat("ppt");
task.setRenderOption(options);
task.run();
irc = task.getReportContext();
task.close();
engine.destroy();
}catch(Exception ex){
ex.printStackTrace();
}
Platform.shutdown();
System.out.println("Finished");
}
/**
* @param args
*/
public static void main(String[] args) {
try
{
RunAndRenderTaskTest ex = new RunAndRenderTaskTest();
ex.runReport();
System.exit(0);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
我使用最新的Zend版本,我想使用Zend公司的Java橋運行BIRT報告,但無法找到zends BIRT API。我卡在那裏。我不能使用tomcat或php的javabridge。我需要將birt報告與經過測試的zend javabridge進行整合。但如何運行報告。 – 2012-02-20 10:03:07
你在尋找什麼? https://encrypted.google.com/search?q=zend+birt給了我很多結果。 – Gordon 2012-02-20 10:14:42
我試着在Zend框架中用zend javabridge實現birt報告。但我缺乏birt API來實現birt報告。 – 2012-02-20 10:17:23