我正在开发一个报告应用程序,用户可以从100个报告的列表中选择(和订购)报告,并要求提供主报告。该主报告应按照确切的顺序包含所有选定的报告,其中的目录列出了主报告中包含的(子)报告和正确的页码。
我如何做到这一点是BIRT?我在此之前使用Pentaho并且能够通过在运行时(即以编程方式)将每个用户选择的报告添加为子报告到主报告来完成相同的操作,该报告实际上是一个占位符报告。
现在我知道BIRT有子报告的概念,但我无法理解BIRT DE API来完成之前使用Pentaho创建主报告所做的事情。那么,我该怎么做呢?
从How do I combine multiple BIRT reports来看,2008年BIRT似乎无法做到这一点。情况仍然如此吗?我不能将独立报告添加为另一份报告的子报告吗?
答案 0 :(得分:5)
经过一些麻烦,我想到了如何实现这一目标。基本上我们必须以编程方式提取每个报告中的所有报告项目,数据集等,并将它们粘贴到新的主报告中。在每个孩子重新学习之后,我确保插入分页符,以便下一页的下一个报告出现。对此的粗略代码是: -
public class ReportGen {
private static ReportDesignHandle reportDesignHandle;
private static ElementFactory elementFactory;
private static ReportDesignHandle reportDesignHandle1;
public static void main(String[] args) {
executeReport();
}
public static void executeReport() {
IReportEngine engine = null;
EngineConfig config = null;
try {
config = new EngineConfig();
config.setBIRTHome("/home/vineeth/Softwares/birt-runtime-2_6_2/ReportEngine");
config.setLogConfig("/home/vineeth/Softwares", Level.FINEST);
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("/home/vineeth/cash_flow_summary.rptdesign");
SessionHandle sessionHandle = DesignEngine.newSession(null);
reportDesignHandle = sessionHandle.createDesign();
elementFactory = reportDesignHandle.getElementFactory();
reportDesignHandle1 = (ReportDesignHandle) design.getDesignHandle();
DesignElementHandle cashflow = reportDesignHandle1.findElement("cashflow");
DesignElementHandle designElementHandle = reportDesignHandle1.getBody().get(0);
if (designElementHandle instanceof ExtendedItemHandle) {
ExtendedItemHandle itemHandle = (ExtendedItemHandle) designElementHandle;
ExtendedItem item = (ExtendedItem) itemHandle.getElement();
ExtendedItem newItem1 = (ExtendedItem) item.doClone(CopyForPastePolicy.getInstance());
newItem1.setName("cf1");
newItem1.setProperty(DesignChoiceConstants.CHOICE_PAGE_BREAK_AFTER, DesignChoiceConstants.PAGE_BREAK_AFTER_ALWAYS);
ExtendedItemHandle newItemHandle1 = new ExtendedItemHandle(reportDesignHandle.getModule(), newItem1);
reportDesignHandle.getBody().add(newItemHandle1);
ExtendedItem newItem2 = (ExtendedItem) item.doClone(CopyForPastePolicy.getInstance());
newItem2.setName("cf2");
newItem2.setProperty(DesignChoiceConstants.CHOICE_PAGE_BREAK_AFTER, DesignChoiceConstants.PAGE_BREAK_AFTER_ALWAYS);
ExtendedItemHandle newItemHandle2 = new ExtendedItemHandle(reportDesignHandle.getModule(), newItem2);
reportDesignHandle.getBody().add(newItemHandle2);
ExtendedItem newItem3 = (ExtendedItem) item.doClone(CopyForPastePolicy.getInstance());
newItem3.setName("cf3");
newItem3.setProperty(DesignChoiceConstants.CHOICE_PAGE_BREAK_AFTER, DesignChoiceConstants.PAGE_BREAK_AFTER_ALWAYS);
ExtendedItemHandle newItemHandle3 = new ExtendedItemHandle(reportDesignHandle.getModule(), newItem3);
reportDesignHandle.getBody().add(newItemHandle3);
DataSourceHandle dataSourceHandle = (DataSourceHandle) reportDesignHandle1.getDataSources().get(0);
DataSource ds = (DataSource) dataSourceHandle.copy();
DataSourceHandle newDSHandle = null;
if (ds instanceof OdaDataSource) {
newDSHandle = new OdaDataSourceHandle(reportDesignHandle.getModule(), ds);
}
reportDesignHandle.getDataSources().add(newDSHandle);
DataSetHandle dataSetHandle = (DataSetHandle) reportDesignHandle1.getDataSets().get(0);
OdaDataSet copyDataSetHandle = (OdaDataSet) dataSetHandle.copy();
DataSetHandle copyDSHandle = new OdaDataSetHandle(reportDesignHandle.getModule(), copyDataSetHandle);
reportDesignHandle.getDataSets().add(copyDSHandle);
}
//reportDesignHandle.getBody().add(reportDesignHandle1.getBody().get(0));
//reportDesignHandle.getBody().add(reportDesignHandle1.getBody().get(0));
IReportRunnable newDesign = engine.openReportDesign(reportDesignHandle);
IRunAndRenderTask task = engine.createRunAndRenderTask(newDesign);
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFileName("/home/vineeth/Softwares/out.html");
options.setOutputFormat("html");
task.setRenderOption(options);
task.run();
task.close();
engine.destroy();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
Platform.shutdown();
}
}
}
答案 1 :(得分:1)
不是尝试在运行时动态地将报表拼凑在一起,而是构建包含其中所有100个组件的主报表可能更容易。然后使用值填充每个组件(或子报表)的书签属性。最后,默认情况下将每个组件的visibility属性设置为“false”。
在运行时,当用户选择要查看的子报表时,可以将所需的子报表作为参数传递,此时可以切换visibility属性,以便只显示所需的子报表。
这比编写大量编译代码要容易得多,并且可以随时随地添加和删除子报表,而无需编写任何代码。
祝你好运!