This sample shows how to copy the same components
StiPage
,
StiHeader
and others between different reports. For example, let's use two reports OriginalReport and CustomReport.
First, you need to deserialize reports from files:
...
StiReport originalReport = StiSerializeManager.deserializeReport(
StiResourceUtil.getStream("/com/stimulsoft/samples/OriginalReport.mrt"));
StiReport customerReport = StiSerializeManager.deserializeReport(
StiResourceUtil.getStream("/com/stimulsoft/samples/CustomReport.mrt"));
...
Then you can copy the components. For this purpose, the serialization can be used:
...
StiHeaderBand originalHeader = (StiHeaderBand) originalReport.getComponents().get("HeaderBand1");
int originalIndex = originalHeader.getPage().getComponents().indexOf(originalHeader);
originalHeader.getPage().getComponents().remove(originalIndex);
StiHeaderBand customerHeader = (StiHeaderBand) customerReport.getComponents().get("HeaderBand1");
String originalHeaderStr = StiSerializerControler.serializedObjectAsString(customerHeader);
StiHeaderBand newCustomerHeader = new StiHeaderBand();
StiDeserializerControler.deserializeFromString(originalHeaderStr, newCustomerHeader);
newCustomerHeader.setPage(originalReport.getPages().get(0));
originalReport.getPages().get(0).getComponents().add(originalIndex, newCustomerHeader);
newCustomerHeader.setName(StiNameCreation.createName(originalReport, "HeaderBand"));
for (StiComponent component : newCustomerHeader.getComponents()) {
component.setPage(originalReport.getPages().get(0));
component.setParent(newCustomerHeader);
component.setName(StiNameCreation.createName(originalReport, component.getName().replaceAll("\\d*", "")));
}
...
In the screenshot below you can see the result of the sample code: