Applying Multiple Templates

Because any report could be used as a template, it is also conceivable that many reports could be applied to any single report as a template.

This can prove quite useful if the templates are doing different things. For example, one template might be applying the standard page headers and footers to all reports within a company, whereas another template could be used to apply department-based colors to the details section. Because both templates are encapsulated separately, they can be applied separately and will not affect each other. The end result is one report with both the corporate style (headers and footers) as well as the specific department's colors (in the Details section) applied.

TIP

Templates can be applied repeatedly, even if new fields are added to the report after the initial template was applied.

Simply choose Reapply Template in the Template Expert to have the template address any new fields.

Crystal Reports in the Real WorldStandardized Templates

Arguably the most powerful use of report templates is simply adding consistent headers and footers. As described previously, the job of placing header and footer information in exactly the right place time after time is time-consuming and boring. A very simple template can give you a head start on basic formatting.

To create your template, an image of the company logo will be used. For this example, the Business Objects logo (saved in JPG format) from the corporate Web site is used.

  1. Begin by creating a new report without a data source, as described earlier in the chapter. Your starting point should look like Figure 14.12.

     

    Figure 14.12. A blank canvas for the report template.

     
  2. From the Insert menu, choose Insert, Picture. Browse for the logo.jpg file and add it to the top left of the report header. In the top right, add a text object and label it Data as of: and right justify the text. Add the special field Data Date to the right of the text.

     

  3. Add the special field Report Title to the page header, center justify the text, widen the field so it reaches to both edges of the report, change the font to 14, and add some vertical height so the text fits properly.

     

  4. In the page footer, add the special field Page N of M, centered with the field stretched to both left and right edges of the canvas. The template is now ready to be applied to all reports, effectively standardizing fundamental elements of report look and feel (see Figure 14.13).

     

    Figure 14.13. A sample standardized template.

     

    NOTE

    To maximize flexibility, ensure that objects (like the logo) used in the template make full use of the repository. Not only is it important to standardize the look and feel, it should also be easy to update.

  5. Save the template as StandardTemplate.rpt.

     

Категории