經過一番麻煩,我想出瞭如何實現這一點。基本上,我們必須以編程方式提取每個報告中的所有報告項目,數據集等,並將其粘貼在新的主報告中。在每個孩子重新使用後,我確保插入一個分頁符,以便下一個報告出現在下一頁。這樣做的一個粗略的代碼是: -
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();
}
}
}
我沒想到這種做法起初,但放棄了它有2個原因: - 1)它不會滿足於生成報告的重要要求訂單是由用戶選擇的; 2)報告最常被創建,但技術上不是那麼專業。這種方法給報告的設計階段帶來了很多複雜性,這是我不想要的。我很高興能夠在代碼中提高這種複雜性。 – Vineeth 2011-03-23 19:46:38
所有優點。對不起,這個想法沒有足夠緊密與您的需求... – MystikSpiral 2011-03-23 22:11:34
請你可以在這裏舉一個例子 - 至於如何建立一個主要報告的組件?至於如何將一份主報告中的所有報告保留在沒有任何分頁符的情況下?我無法在birt樣本中的任何地方找到多頁報告...謝謝! – Anna 2012-05-02 04:33:18