Crystal Reports Templates


Crystal Reports Templates

You may have created a report that contains a large amount of custom formatting that you d like to apply to other reports all at once. You may user Report Templates for this purpose. Report Templates are just existing .RPT files that are used to format other reports. One of the first places you may notice use of report templates is on the last screen of report wizards that you can use when first creating a new report.

click to expand

To apply a template in a report wizard, simply select one of the predefined templates in the Available Templates list. When you choose one of the templates in the list, a thumbnail view of the template is shown in the Preview section of the report wizard. You may also choose another .RPT file to use as a template by clicking the Browse button. This will launch a standard open file dialog box, where you can navigate to the existing .RPT file you wish to use as a template.

Once you ve chosen the report, it will be added to the template list, where you may select it to control the formatting of the new report. If the report you added has a value in the File Summary Info Title field, it will appear as the name of the template. And if the Save Preview Picture check box is checked in the File Summary Info dialog box of the report you just added, the preview of the report will appear in the Preview area of the report wizard.

Note  

Any .RPT files you add to the template list won t remain in the list the next time you use the report wizards. You ll need to navigate to the report with the Browse button again if you want to use it as a template.

The Template Expert

If you want to apply a template to a report you ve already created (either with a report wizard or without), you can use the Template Expert to apply a template or undo the previous application of a template. To display the Template Expert, either click the Template Expert toolbar button in the Expert Tools toolbar, or choose Report Template Expert from the pull-down menus . The Template Expert will appear, as shown in Figure 9-9.

click to expand
Figure 9-9: The Template Expert

The Template Expert looks very similar to the Template section of the report wizards, with a few additional features. As with the report wizards, you can pick a template from the list to add to your current report. When you select a template in the list, a preview of the template will appear in the Preview area of the Template Expert. And you may also click the Browse button to add an existing .RPT file to the template list to use to reformat the current report.

However, the Template Expert includes a few more features that don t apply to the report wizards. In particular, if you ve already applied a template and aren t satisfied with its results (and this is a real possibility ”templates can dramatically change the formatting of your report), you can undo the template application by clicking the Undo the Current Template radio button in the Template Expert. This is the only way to undo a template application ”the Undo feature on the Edit menu or the Undo toolbar button won t undo a template application. If you ve already undone a template and wish to redo it, you may either choose it in the template list again or click the Re-Apply the Last Template radio button. It s important to remember that the Undo and Redo features will be available only during the current Crystal Reports session. If you apply a template, save the report, and then exit Crystal Reports, you ll be stuck with the template s formatting when you next reopen the report.

Tip  

The predefined templates in the Template Expert are supplied by existing .RPT files. By default, Crystal Reports looks in \Program Files\Crystal Decisions\Crystal Reports 10\Templates for template reports. If you wish to change the location that Crystal Reports uses to populate the Template Expert, you must change the Registry key HKEY_LOCAL_MACHINE/Software/Crystal Decisions/10.0/Crystal Reports/Templates/TemplatePath. Ensure you are familiar with manipulating Registry settings before attempting this change.

Once you ve chosen a template to apply to your current report, the report s formatting will change, often drastically. How Crystal Reports applies all the individual object and section reporting of the source template to your current report is not necessarily predictable ” you ll want to experiment with several templates to see how they affect formatting. However, as a general rule, Crystal Reports will compare report objects and report sections between the template and the current report, applying many of the formatting properties of both report sections and individual objects in the template to the current report. If, for example, the template report contains two details sections (Details a and Details b) and the current report contains only a single detail section, the current report will have an additional details section added when the template is applied. If you have a chart in the template but not in your current report, a chart will be added when the template is applied. And if your template contains ten details section fields formatted with different colors, you can generally expect the template s formatting to be applied to the first ten objects in the details section of your current report.

If you plan on using a template, you probably won t want to do a great deal of formatting to your original report before you apply the template ”your pre-template formatting will be discarded. If you are generally pleased with a report s formatting, you would be well advised to save the report before applying templates. While the Undo capability exists in the Template Expert, you ll want to play it safe in case you may not want to permanently accept a template s formatting changes.

Tip  

You are not limited to applying one template to a report, but may apply as many as you d like by following the previous steps more than once. Depending on which templates you apply, these multiple template applications will blend together to form a report that combines the formatting options from all templates applied. In other cases, one template will completely replace another.

Creating Your Own Templates

As mentioned previously, templates are merely other Crystal Report .RPT files whose formatting is copied to the current report. While the few sample templates that are already provided by Business Objects are acceptable for exploring the capabilities of adding templates, you ll probably want to develop a set of templates that conform to your company s look and feel, perhaps including a company logo, preferred font face and size , and various object and section formatting standards that you wish to commonly apply to reports.

You may want to begin by just picking some already-created standard reports that approximate the look and feel you desire . You can then experiment with using them as templates. You may wish to save them in a temporary folder and modify the original reports to make better use of them as templates. Once you ve modified the existing template reports to meet your needs, you may add an appropriate name to the Title field in the File Summary Info dialog box, as well as checking the Save Preview Picture check box in the same dialog box. Then, preview the report (this is required to generate the preview picture) and save the report into the template directory. That report will now appear as a template in the Template Expert and Report Wizard Template section.

You may also wish to create a new report from scratch to act as a template. Crystal Reports includes a special type of field known as the template field to help in this endeavor. A template field is a special kind of field you can add to a report to act as a placeholder for a report object when applying the template to the main report. A template field doesn t initially display any data ”it just contains formatting information that is carried over when the template is applied to the main report. To insert a template field, choose Insert Template Field Object from the pull-down menus. An object outline will be placed on your mouse cursor. Drag the object to its desired location on the report and click to drop it. The template field will be added to the report.

click to expand

You now select the template field and format it with any of the methods discussed earlier in this chapter. However, you ll notice one unique difference between template fields and regular database fields when you format them with the Format Editor: tabs for every possible data type will appear in the Format Editor when formatting a template field. This additional template field flexibility lets you set up formatting for various target report fields that you may use with this template report. For example, if you re not sure whether the first field in the details section of the target report will be a string, number, or date, you can use the Paragraph tab, the Number tab, and the Date and Time tab to set formatting for the template field. When the template field is used to apply formatting in the target report, the formatting you ve chosen in the appropriate tab will filter to the target fields.

When using template fields in a template report, it may be difficult to see what the actual target report formatting may look like. This is because template fields, by default, aren t connected to any database fields. As such, they won t show any data if you try to view your template report in the Preview tab. However, you can set template fields to display a value in the Preview tab by using the Formula Workshop. Notice that when you add a template field to the report, a corresponding formula is added to the Field Explorer. If you edit the template field formulas (editing formulas is discussed in detail in Chapter 5), you can change the formula to return something other than ten spaces, which are initially returned by the formula by way of the Space(10) function. You may replace the Space(10) function with a database field from the Field tree, or another function from the Function tree that will return data. When you display the template report in the Preview tab, you ll now be able to more accurately determine how the resultant formatting will be applied in the target report.

Once you ve used template fields to create the template report, supply a name for the template in the Title field of File Summary Info. You may also wish to check Save Preview Picture, preview the template report (which is required to save the preview picture), and then save the template report to the folder where other template reports are located. You will then see the new template appear the next time you need to apply a template with the Template Expert or in the report wizards.

Tip  

A detailed chart discussing how objects and report sections in templates interact with the main report can be found in Crystal Reports online help. Search help for templates, considerations.




Crystal Reports 10
Crystal Reports 10: The Complete Reference
ISBN: B005DI80VA
EAN: N/A
Year: 2004
Pages: 223
Authors: George Peck

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net