Flylib.com

Books Software

 
 
 

Understanding Report Templates

Understanding Report Templates

A report template is nothing more than a regular report (RPT) file. It can be any RPT file. Templates are applied to other reports so that their formatting and layout can be used as a basis for the other reports. What is useful about the application of templates to other reports is that formatting is applied to the report as well as the layout. An example of this would be a report that has four fields in a detail section, where all sections are " squished " together before applying a presentation-quality template. After the template is applied, the location of the fields in the template would force the fields in the existing report to span out and possibly even change some font information, depending on the specific template.

Using Report Templates

Think of a template as the form that everyone in a company must comply to. Templates can house many types of objects. These objects can be applied to a report after the data- intensive portion of the report design is completed. Applying an existing template to a report can save hours or potentially days of mundane formatting tasks .

Some types of tasks that can be accomplished by (but are not limited to) applying a template to a report are as follows :

  • Corporate logos and other images

  • Consistent page numbering formatting

  • Font style/ color /typeface for data fields

  • Field border and background formatting

  • Field sizing

  • Group headers and footers formatting

  • Summary field formatting

  • Watermarks

  • Tricky formatting

  • Lines

  • Boxes

  • Repository objects

  • Report titles

  • Website links

  • Formatting based on data-field type

How Are Templates Better Than Styles in Previous Versions?

Templates are better than the Styles in prior versions of Crystal Reports in so many ways that it's challenging to explain in a short coffee break topic. However, because not every report designer has used Crystal Reports prior to version 9, it's a worthwhile subject. (For those of you new to Crystal Reports with this version, feel free to skip this coffee break.

The main issue with the old feature of Report Styles in previous versions of Crystal Reports (such as 8.5) was that they were not customizable. The styles that one person created when the feature was initially introduced were the only options available. Even if you just didn't like the color red as the group name field and wanted to change it to blue, you were not able to, which was very limiting. This limitation alone made the Styles feature practically useless outside of learning how to create very simple reports.

These styles were also limited to data and group fields. No images or static text objects were included, and again because the styles could not be modified, they could not be updated in this way. The styles were hard-coded into the Crystal Reports designer so that no external RPT files were used, whereas Templates allow the use of any RPT file.

Using Existing Crystal Reports as Templates

Now that we've introduced the major benefits of Report Templates, let's actually apply a template to one of the reports created in an earlier hour. The report in Hour 5 is a good example.

The report as it looked in Hour 5 was pretty plain because the focus was on making sure that the data requirements were satisfied. There wasn't a lot of time to play with formatting, so now we are going to apply a template that has some nice grayscale formatting and an underlay applied.

  1. Open the report. Choose File, Open to get the Open dialog box, and browse until the report is found. (The report is probably named CHAP5.RPT). Choose it and click Open to continue.

  2. Look at the report prior to applying the template as shown in Figure 19.1. To get a good view of the application of the template, make sure that the Preview tab is selected. If the Preview tab is not selected or available, choose View, Preview.

    Figure 19.1. The report from Hour 5 as it appears in Preview.

    graphics/19fig01.jpg

  3. Apply the template. To apply some formatting quickly, choose Report, Template Expert. In the Template Expert dialog, feel free to choose each file so that you can see the associated thumbnail. For this case, let's choose Confidential Underlay, as shown in Figure 19.2, and then click OK.

    Figure 19.2. The Template Expert with the Confidential Underlay template chosen .

    graphics/19fig02.jpg

    graphics/lightbulb_icon.gif

    For more information on thumbnails, review the Preview Pictures coffee break at end of this hour.


  4. Save the report. The report will then open with the formatting from the applied template as shown in Figure 19.3. You can now save the report as CHAP19.rpt .

    Figure 19.3. The target report with the Confidential Underlay template applied.

    graphics/19fig03.jpg

graphics/bookpencil_icon.gif

You might have noticed that just about anything you do when designing a report can be undone if you don't like it. This is also true when applying templates. However, the mechanism of accomplishing this is slightly different from all other undo operations. It does not appear in the regular undo list on the Standard toolbar.

If you don't like a template that you've just applied or it doesn't accomplish what you had hoped for, you can undo this action by going back in to the Template Expert. At the bottom of the dialog box, you will find a button that says Undo the Current Template. After selecting it and clicking OK, the template is removed.


Understanding How Templates Work

A lot of report formatting tasks were accomplished in the two minutes it took to apply the template in the previous exercise, including

  • Adding the Powered by Crystal logo to the report (along with its ToolTip and hyperlink) from the Crystal Repository. The Crystal Repository is discussed in more detail in Hour 18, "Working with the Report Component Repository."

  • Adding an image that says Confidential as an underlay to each page of the report.

  • Modifying the fonts and positions of all the database fields.

  • Showing the Record Selection Formula on the report.

  • Adding dashed lines between all items in the Details Section.

  • Adding a rounded box around the Record Selection Formula.

  • Using a rounded box to show where groups start and end.

  • Moving the Field Headings for each data field into the Group Header and formatting them with double lines.

graphics/lightbulb_icon.gif

One of the more advantageous features of templates is that even if more fields are in the target report's Details section than the template has, it duplicates the data field formatting for those extra fields. It puts them into a separate Detail Section (usually titled Details B) so that they will all appear together but they won't overwrite each other. The fields can then be moved around without having to worry about applying the same formatting by hand.