Formatting Report Sections 182
Modifying Report Section Properties 186
Using Multiple Report Sections 195
Crystal Reports in the Real World—Advanced Formatting 201
You should now be familiar with some of the most common formatting features within the Crystal Reports XI designer. Building on the concepts and techniques covered in Chapter 6, “Fundamentals of Report Formatting,” for report object formatting, this chapter explains how you can format entire sections within your reports. Just as any report object has specific modifiable properties available for formatting, report sections also have unique properties.
For more information on report formatting, see “Exploring the Format Editor Dialog Common Options,” p. 168.
In this chapter, these properties are examined and their use in creating effective professionally styled reports is explored.
This chapter covers the following topics:
The earlier chapters introduced the concept of report sections such as the detail section and the group header and footer sections. Report sections segment reports into logical areas that facilitate logical report design. Report sections are identified by name on the left side of the design environment, and, by default, each report includes a Report Header and Footer, Page Header and Footer, and Details section. If you have inserted any groups into your report, you also have a Group Header and Footer for each defined group item. As reports have been created in the previous chapters, objects such as database fields, text fields, and corporate logo images have been placed into the various report sections and organized based on the report design requirements.
Each section has unique display properties and printing characteristics that can be modified. For example, if a report object, such as an image, is placed in the Report Header section, the image displays and prints only once per report, on the first page. If the same image is placed in the Page Header section, the image then displays and prints once for every single page of the report. The same principals hold true for other custom sections, such as Group Headers and Footers. Finally, the Detail section implies that whatever is placed in this section displays, and prints, once for each and every row retrieved from the data source.
The Crystal Reports design environment is built on a paper metaphor with pages the driving concept in structuring the presentation of report information. This page metaphor applies when referencing report printing and with respect to various presentation characteristics of report formatting.
Using the report created in Chapter 6, you will take a closer look at how to format report sections. The following exercises demonstrate how to format sections such as the Group Header and Group Footer to improve the overall presentation of a Crystal Report. In addition to modifying display properties, conditional logic is also applied that modifies the behavior of the Page Header section based on the result of the defined condition (format formula). The Section Expert is the central location for working with all report section properties, and it is used to view and modify the properties of each report section throughout the following exercises.
As you might have noticed, long names (descriptive names) of each section are provided to the left of the design environment within the Design tab, whereas only the short names (abbreviated names) of sections are presented while viewing reports from the Preview tab. This maximizes the report viewing space while working in the Preview tab. The long names can, however, be accessed by either hovering the mouse cursor over the section or by right-clicking on the section name (or label).
There are three distinct ways to access the Section Expert; these include
To start the hands-on learning, follow these steps:
From within the Section Expert, you can easily navigate from modifying the properties of one report section to another without closing this dialog window. Regardless of how you open the Section Expert dialog window, you can quickly toggle to other report sections, providing a central location to access and modify the properties of all report sections.
• Customer.Contact Last Name field from the Choose the Field to Summarize drop-down list
• Count from the Calculate This Summary drop-down list
• Group #1: Customer.Country from the Summary Location drop-down list
To access the Insert Summary dialog so that you can add a summary field to your report, you can use the Summary command from the main Insert menu, you can use the Insert Summary button located on the Insert toolbar, or you can simply right-click on any report field already in the report and access the Insert Summary menu option from the right-click menu. This last option pre-populates the Choose the Field to Summarize drop-down box and saves you one needless step.
As you have seen, formatting the various sections of your report is very straightforward. Each section has unique and specific properties that can be modified and used collectively to enhance the presentation quality of the entire report.
To quickly remove blank space within report sections and tighten up the alignment of the objects positioned within the sections, you can use the Fit Section command. The Fit Section command is available from the right-click menu of each report section. This raises the bottom boundary line and reduces unnecessary space within the section.
In addition to formatting properties, each section has a variety of general properties that can be used to manipulate the behavior of that section within the overall report. For example, if you would like to suppress a particular section from the report display or just hide a detail-oriented section from the initial display but enable business users to navigate to the underlying details, you can use the Section Expert to accomplish this.
Using the report you created in the previous exercise, relocate the Count summary field into the Group Header and hide the Details section to enable the viewer of the report to access this section only if he double-clicks on the Group Header summary values—commonly known as drilling-down on report data. The following steps guide you through formatting several fields and sections, creating a drill-down report:
Common report section commands—such as Hide, Suppress, Delete, Hide Section Names, and Select All Section Objects—are accessible via the pop-up menu when you right-click on the applicable section’s name. Some of these commands are also available within the Section Expert dialog, although unlike the Section Expert, the right-click pop-up menu pertains only to the specific section you have selected.
Count ({Customer.Contact Last Name}, {Customer.Country}) > 5
This formula is evaluated for every Group Footer (for every country) and will only cause a New Page After the involved Group Footer when the current country has more than five contact names.
Exploring the end users behind this hypothetical example a bit more, it is likely that the majority of the business users for this report are primarily interested in the total number of contacts for each country rather than the actual list itself. However, a few of the business users also want to be able to access the complete contact list on occasion. To accommodate both groups of users, you can manipulate the properties of the Details section.
Drill-down functionality is designed to make report viewing easier. You can hide the details of your report and only have the group headers and summaries visible, and, when necessary, the business users of the report can then click on the group header or summary fields to view the report details.
To indicate to the business user of the report that more detailed information is available behind the summary group level, the mouse pointer turns into a magnifying glass icon when it floats over a drillable section (for example, the yellow count field of customer contacts, located in the Group Header #1 section).
As shown in Figure 7.5, a list of each country with the total number of contacts displayed has now been created. Additionally, upon double-clicking the count of contacts (displayed with the underlined, yellow number) the business user of the report is quickly able to drill-down into the Details section and be presented with the actual customer contact specifications.
As you can see in Figure 7.6, after the business user drills down into a particular group’s detail listing (France in this example), that group’s detailed contact list is displayed in the Crystal Reports application in a separate tab and is cached so that it can be easily accessed for future reference. When a business user of the report selects a refresh on the report, all cached tabs are removed because there is no guarantee that the data being retrieved from the database would be the same as the previously cached page. The end user would have to drill back down into France if he wanted to view the detailed contact listing again.
As discussed to this point in the chapter, the Section Expert provides a great deal of powerful report formatting functionality and flexibility. There are two major areas to the Section Expert as shown in Figure 7.4—the Sections area and the Formatting tabs (Common, Color, and Layout). This section presents each of these sections and their associated functionality.
The Sections area is composed of a listing of all the current report’s sections and five separate buttons—Insert, Delete, Merge and the up and down arrows. The Sections area takes up the entire left half of the Sections Expert dialog and enables you to create, delete, merge, and reorder entire sections within the involved report. The following list describes each of the Section Expert Sections area components:
In addition to the Section Expert options that you have already used, the following segment of the chapter provides an overview of the available settings presented on the Common tab of the Section Expert. A subset or all of these options are made available when a section is selected in the Sections area, as described previously. The following options are made available in the Common tab:
1
) for the following page after it prints a group total. When this option is used in conjunction with Print at Bottom of Page, a single group prints on a page, the group value is printed at the bottom of the page, and the page number is reset to 1
for the next page. This option is useful whenever you are printing multiple reports from a single file (such as customer invoices), and you want each report to be numbered beginning with Page 1.The presence of the x+2 buttons to the right of the majority of the options indicates that those options can be set via a formula in addition to setting them via the dialog. When an option is set via formula, this is referred to as conditional formatting because the formula typically evaluates a condition.
To implement a conditional option, click on the x+2 button associated with the option and the Formula Editor is presented. Within the Formula Editor, a formula needs to be created that is evaluated for every iteration of the section. If the formula evaluates to a value of True, the involved option is applied; otherwise, it is not. A simple but practical example of conditional section formatting could be a marketing campaign list where the marketing department wants to contact customers in the USA by phone and everywhere else by mail. Two detail sections could be created, one that includes Contact Name and Phone Number, the other with Contact Name and Mailing address. The first section can be conditionally suppressed on the following formula—{Customer.Country} <> "USA"
to only show that section for USA-based customers. The second details section would be conditionally suppressed with {Customer.Country} = "USA"
to only show non-U.S.-based customers.
Use the Color tab to set the background color for the entire highlighted section. This can be done absolutely or conditionally. A good example of a conditionally colored background is when presenting a lengthy list of detailed items. To enable easier reading of the report, every second row can be conditionally colored Silver with the following formula:
The Layout tab only appears when you have the details section selected and the Format with Multiple Columns check box has been selected on the Common tab. This tab enables multi-column formatting. As described earlier, this kind of report enables you to present multiple columns of standard row data and have the data flow from column to column. This tab, shown in Figure 7.7, has four distinct settings:
When you format a report to show multiple columns, the Crystal Reports engine reviews the fields in the detail section and sizes the columns in the rest of the report based on the width of those fields. As such, if data labels (text fields) are placed in the detail section for row identification, these increase the width of the report’s columns and reduce the number of columns that fit onto a page. To place such fields, consider placing them in a Page or Group header and underlaying them onto the Details section.
To begin to truly understand the powerful formatting capabilities of multi-column reporting, it is instructive to edit your current contact list report using this functionality. Figure 7.8 highlights some appropriate layout settings you can set after you have checked the Format with Multi-Columns check box (remember that it’s only available for the Detail section). At this time, do not check the Format Groups with Multiple Columns option but rather simply set the Width and Gap options. You will also need to increase the height of the Details section and stack the current Details columns one on top of the other for the best display effect.
The results of this small report modification are seen in Figure 7.9. You can see that the report now shows the pertinent customer contact information in multiple columns across the page. This flexibility is often effectively used in the creation of financial statements and other reports where a columnar display paradigm is natural or expected.
Including multiple sections within each section area of your report provides for an extremely flexible presentation of your report data. Chances are good that you do not need to create more than one occurrence of any of the existing report sections for basic reporting needs. However, Crystal Reports enables you to define multiple report sections within any given section area and to identify section-specific properties for challenging formatting requirements within more complex reports. Certain reporting tasks are performed most efficiently by creating multiple sections within an area.
For example, multiple report sections would be very useful if you want to create a form letter for your customers and you need to display only one of two possible return addresses on the letter—an American address for customers based in the United States and a Canadian address for the Canadian customers. To accomplish this, you do need to insert two report header sections into your report and use Conditional Formatting to dynamically apply the appropriate return address based on where the customer is located.
To demonstrate how to implement and use multiple report sections, you first need to review the basic operations of resizing, inserting, removing, and merging report sections.
Report sections might require resizing to accommodate for various sized report objects, such as large database fields, lengthy text objects, or corporate logo images, but they cannot exceed the size of the report page itself. From the Design tab of the report environment, you can drag the bottom boundary of the various sections up and down with the mouse to resize each section. Using the mouse, float the pointer over the horizontal boundary lines of the different sections. When the mouse pointer changes into a double-headed arrow icon, click and hold the left mouse button while dragging the boundary line to the desired position.
To display only one of two possible return addresses on a form letter based on the country of the customer, you need to insert a second page header onto the report. The following steps walk you through constructing the following report using the Customer table from the Xtreme Sample Database:
Notice that in this sample form letter report, each report object displayed on the report is just a text object inserted into the appropriate section. There are no database fields included in the report yet.
Next you will insert a new Page Header in which to display an alternate return address for Canadian customers. The following steps will take you through this process:
Now that the report has the two different return addresses and report sections created, the logic must be created within the report to implement the appropriate Page Header section based on each customer’s location—whether they are based in the United States or Canada. Each customer’s mailing address needs to be evaluated—the Country field from the Customer table. For this example, you’re only concerned with North American customers, and if this field is equal to USA, use Page Header a to display the return address. If it is equal to Canada, use Page Header b.
Dear {Customer Name}
in the Design tab of your report. To do this, you’ll need to modify the text portion of this combined object to read “Dear” (the word Dear followed by a space), and then followed by the database field object.
Finally, you need to apply the logic to display the appropriate return address on the form letter. To do this, you apply a conditional formatting statement (format formula) to each of the two Page Header sections.
{Customer.Country} = "Canada"
. After you have inserted this statement, click Save and Close to return to the Section Expert. Note that the x+2 button has changed color (to red) to signify a conditional formula has been created here.
{Customer.Country} = "USA"
.
You do not need to check the Suppress (No Drill-Down) check box in the Section Expert dialog for either report Page Header section. By inserting a format formula, you have effectively applied conditional formatting that suppresses the section if the format formula is found to be true. In this case, one of the two format formulas should always be true because the customers are either located in the United States or Canada.
In much the same manner sections were inserted, unused report sections can be removed from reports quickly by right-clicking on the section name and selecting Delete Section from the pop-up menu. Be aware, however, that any report objects positioned within the section are also deleted from the report. If any of the objects within a section that will be removed are required, they will need to be relocated into alternative report sections before deletion.
Crystal Reports requires at least one section to be present for certain section types in every report—the Report Header and Footer, Page Header and Footer, and Details sections. These report sections are generated by default when creating new reports. Also, if Group objects exist within a report, you cannot remove the Group Header and Footer sections unless you first remove the Group object itself from the report.
When designing reports, you might periodically want to merge two report sections to simplify the layout of a report. To merge the two Page Header sections from your earlier example, right-click on the Page Header a section title and select Merge Section Below from the pop-up menu. The Merge Section Below command is available from the right-click menu of any report section that meets two criteria:
For example, if three Page Header sections are present on a report (as shown in Figure 7.14), the Merge Section Below command would be accessible from the right-click menus of Page Header a and Page Header b, but not from Page Header c.
I keep getting blank spaces above and/or below my data fields in my report sections, and I need a quick way of removing them.
To quickly remove blank spaces within report sections and tighten up the alignment of the objects positioned within the sections, use the Fit Section command available from the right-click menu of each report section.
I want the Group headers of each Group Section to be shown as I drill-down into the report’s grouping hierarchy. By default, this does not happen and creating conditional suppress functions on each section can be time consuming.
To change the default behavior to always show Group Headers on drilling down, access the Report Options dialog from the File menu and check the Show All Headers on Drill-down option box.
Often, a report section needs to be more than simply one color or another. A report with many rows might need some color to help guide the reader’s eye and make each line distinctly separate from the next. In the following sample, the report created earlier is modified to improve readability: