Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

8.09 Designing with Report Templates

Designing with Report Templates

Report templates make it easy to create reports that all have common formatting. This can save you a considerable amount of time because you don’t have to format the objects on a report individually. The template formats all the objects at one time.

Report templates work by examining how the report objects in a template are formatted and applying those same formatting rules to an existing report. The formatting properties of the existing report are overridden by the template and the report takes on the appearance of the template. Report templates make it easy to give your reports a consistent look and feel.

You’ve already seen how Crystal Reports makes it easy to create reports that use consistent formatting. The Options dialog box has a Fields tab and Font tab that sets the default formatting of each type of report object. For example, you can set Field objects to be Arial with a size 10 and you can set String objects to have a thin border. Every string object added to the reports takes on that formatting. But this has its limitations because report formatting is a much more granular process. Strings can be formatted one way in a group header, and have a totally different formatting in the details sections The Options dialog box is too generic to take this into account. It gives you a good start and saves you a little time, but there is still work to be done to make the report look polished. Another limitation with the Options dialog box is that it doesn’t take into account the positioning of objects on a page and more global aspects of a report, like having a corporate logo at the top and formatting page numbers a certain way at the bottom of a page. Templates make up for the short-comings of the Options dialog box.

You’ve already had a brief introduction to templates when using the Report Wizard. The final step of the Report Wizard lets you select the report template for applying default formatting. Crystal Reports installs a set of default report templates to give you a head start on formatting your reports.

You aren’t limited to using the report templates that are installed with Crystal Reports. You can use an existing report as a template or you can create custom templates as well. Creating custom templates lets you specify graphics and color schemes that display the logo and match the corporate image. We’ll talk more about custom templates in a later section.

Applying Report Templates

Crystal Reports makes it easy to apply a report template. Select the menu items Report > Template Expert. This opens the Template Expert dialog box. It shows a list of the available templates along the left side and on the right side is a preview of the currently selected template.



Figure 8-14. The Template Expert dialog box.

Crystal Reports gives you over a dozen pre-built templates to work with. You can use any of them for your own reports. If there isn’t a template that you like but you have an existing report that you’ve used in the past, then you can use it as a template also. The Browse button on the bottom left-hand corner lets you select an existing report as a template file.

After clicking the Browse button and finding the report you want to use as a template, it appears in the Available Templates list. When you click on it in the list, you’ll see a thumbnail of it in the Preview window to the right. Unfortunately, the new report template doesn’t stay in the Template Expert after you close it. You’ll have to click the Browse button each time you want to use that report as a template. If you want it to appear in the list of available templates permanently, copy it to the folder:

C:\Program Files\Business Objects\Crystal Reports 11\Templates\en

As you might imagine, for Crystal Reports to properly map a template onto a target report, it has to do a lot of analysis of every report object. After clicking the OK button to apply the template, the report is temporarily hidden while Crystal Reports processes it. Objects that don’t exist in the target report will be added. This includes charts, graphics and special fields. If the target report has extra fields in the Details section that don’t map directly to the template, then new sections are created on the report and the additional objects are placed in these sections. No objects are deleted. Once Crystal Reports finishes processing the template, you will see the report again with the template applied.

If applying a template doesn’t give you the results you expected, you can undo it and return the report back to the way it was. The radio button at the bottom of the Template Expert dialog box lets you undo the template changes and restore the original report format. If you later decide that you do want the template, then the other radio button lets you re-apply the template.

The caveat to using the Undo option is that you have to do this immediately after applying the template. If you start making changes to the report and later click the Undo button, it will lose your changes. The Undo button restores the report back to the way it was before you applied the template.

One interesting feature of templates is that they are cumulative. You can apply more than one template to a report and each template builds on the one before it. If you are going to use multiple templates then be aware that the Undo button only goes one level deep. In other words, you can only click the Undo button once. All previous templates are permanent. So make sure you save a copy of the report if you are experimenting with templates.

Templates can only be applied at design time. They cannot be applied while a report is running. For example, let’s say that you have a customer who wants their invoices formatted a certain way that does not use your company’s standard invoice format. You might think that you could use conditional formatting to apply a different template just for that customer. But this won’t work. Instead, you’ll have to do what we discussed earlier and use conditional formatting to modify the individual report objects during runtime. Or use multiple sections and enable the section that applies to that customer.