Applying a report template

Templates allow you to apply predefined formatting, fields, and other items to a report using another report that you have already created. For example, you could create a report that has common features all your reports share, such as common hyperlinks, company letter head, and so on.
To apply a template, you must have a report that will act as a template. You then use the ReportTemplateEngine class to amalgamate the template report with any other report.

Note: Applying a template to a report is similar to applying a style. The difference lies in the flexibility that templates offer. Styles are fixed and predefined, while templates may be customized to meet your needs.
Example: 
The following code applies a report template from an existing report to a target report.

Note: This example uses the applyToDocument method of the ReportTemplate class. You may also use the applyTo method which allows you to pass in a file path to the target report rather than opening it as a ReportClientDocument object.
void applyTemplate (ReportClientDocument templateRCD, ReportClientDocument targetRCD) throws ReportSDKException
{
  ReportTemplateEngine templateEngine = new ReportTemplateEngine();
        
  ReportTemplate reportTemplate = templateEngine.createTemplateFromDocument(templateRCD);
  reportTemplate.applyToDocument(targetRCD);
}
This list includes the classes used by the sample code:
  • com.crystaldecisions.sdk.occa.report.application.ReportClientDocument
  • com.crystaldecisions.sdk.occa.report.template.ReportTemplate
  • com.crystaldecisions.sdk.occa.report.template.ReportTemplateEngine
  • com.crystaldecisions.sdk.occa.report.lib.ReportSDKException