You can programmatically modify the structure of
a subreport. This example shows how to modify the background color of the first
field object in the subreport. The workflow for modifying a subreport is the
same as for modifying a report. Use the main report's
SubreportController class to
retrieve an
ISubreportClientDocument
interface, and then use the standard controllers to modify the subreport.
Get the
SubreportController object from
the main report.
SubreportController subreportController = rcd.getSubreportController();
Get the
ISubreportClientDocument object
using its alias (name).
Note: You can get the name of a subreport by using the
getSubreportNames method of the
SubreportController class.
ISubreportClientDocument subReportClientDocument = subreportController.getSubreport("subreport.rpt"); Get the
ReportDefController object for
the subreport.
ReportDefController subReportDefController = subReportClientDocument.getReportDefController();
Get the first field object in the
subreport.
ReportObjectController subReportObjectController = subReportDefController.getReportObjectController();
ReportObjects reportObjects = subReportObjectController.getReportObjectsByKind(ReportObjectKind.field);
FieldObject object = (FieldObject)reportObjects.get(0);
Create a clone of the field object
and modify its properties.
This example sets the
background color of the field to
java.awt.Color.YELLOW.
FieldObject newObject = (FieldObject) object.clone(true);
newObject.getBorder().setBackgroundColor(java.awt.Color.YELLOW);
To modify the field object, call
the
modify
method of the subreport's
ReportObjectController object.
subReportObjectController.modify(object, newObject);
Example:
This sample sets the background colour to yellow
for the first field object in the subreport.
void modifySubreportDefinition (ReportClientDocument rcd) throws ReportSDKException
{
SubreportController subReportController = rcd.getSubreportController();
ISubreportClientDocument subReportClientDocument = subReportController.getSubreport("subreport.rpt");
ReportDefController subReportDefController = subReportClientDocument.getReportDefController();
ReportObjectController subReportObjectController = subReportDefController.getReportObjectController();
ReportObjects reportObjects = subReportObjectController.getReportObjectsByKind(ReportObjectKind.field);
FieldObject object = (FieldObject)reportObjects.get(0);
FieldObject newObject = (FieldObject) object.clone(true);
newObject.getBorder().setBackgroundColor(java.awt.Color.YELLOW);
subReportObjectController.modify(object, newObject);
}This list includes the classes used by the sample
code:
com.crystaldecisions.sdk.occa.report.application.ReportClientDocument
com.crystaldecisions.sdk.occa.report.application.ISubreportClientDocument
com.crystaldecisions.sdk.occa.report.application.SubreportController
com.crystaldecisions.sdk.occa.report.application.ReportDefController
com.crystaldecisions.sdk.occa.report.application.ReportObjectController
com.crystaldecisions.sdk.occa.report.definition.FieldObject
com.crystaldecisions.sdk.occa.report.definition.IBorder
com.crystaldecisions.sdk.occa.report.definition.ReportObjects
com.crystaldecisions.sdk.occa.report.lib.ReportObjectKind
com.crystaldecisions.sdk.occa.report.lib.ReportSDKException