以下是使用Birt报表引擎在新页面上开始一个章节的代码示例:
import org.eclipse.birt.report.engine.api.*;
public class BirtReportExample {
public static void main(String[] args) {
try {
// 创建Birt引擎
EngineConfig config = new EngineConfig();
config.setEngineHome("C:/birt-runtime-4_8_0/ReportEngine");
Platform.startup(config);
IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
IReportEngine engine = factory.createReportEngine(config);
// 打开设计文件
IReportRunnable design = engine.openReportDesign("C:/path/to/your/report.rptdesign");
// 创建报表任务
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
// 设置输出格式
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFileName("C:/path/to/your/output.html");
options.setOutputFormat("html");
task.setRenderOption(options);
// 设置新页面开始的章节
task.setParameterValue("ChapterStartOnNewPage", true);
// 执行报表任务
task.run();
task.close();
// 停止Birt引擎
engine.destroy();
Platform.shutdown();
System.out.println("报表生成完成!");
} catch (Exception e) {
e.printStackTrace();
}
}
}
在上述示例中,首先创建了Birt引擎,并加载报表设计文件。然后,创建报表任务并设置输出格式为HTML。接下来,通过setParameterValue
方法将ChapterStartOnNewPage
参数设置为true
,以确保章节在新页面上开始。最后,执行报表任务并停止Birt引擎。
请注意,上述代码示例中的路径需要根据实际情况进行替换,以确保能够正确加载报表设计文件和生成输出文件。