Formatting Report Objects

book list add book to my bookshelf create a bookmark purchase this book online

mastering crystal reports 9
Chapter 3 - Formatting Fields and Objects
Mastering Crystal Reports 9
by Cate McCoy and Gord Maric
Sybex 2003

Are you ready to spice up the report with a little color and some visual elements? Imagine a report that consisted of only columns and columns of Times Roman 12 point black text pulled from a data source with no textual information to describe what you’re looking at. Sounds like a fairly ugly report. Let’s learn some techniques to get beyond the basics.

Inserting Text Objects

When you created a report and added database fields to the Details section, text objects containing the field name were automatically added to the Page Header. These became the column headings to describe the fields in the report. So, without intentionally doing it, you’ve already used text objects!

Text objects are elements that you add to a report to do one of two things for you:

  • Add descriptive text information to a report

  • Combine multiple objects for formatting purposes

To add a text object directly, choose Insert > Text Object. The gray placement rectangle appears, and you can then drop the text object into any of the sections. In Chapter 2, we introduced the visual aides of alignment markers, grids, and rulers to help place database fields in a report. These same visual aides can be used with text objects as well.

Once you’ve placed a text object in a report, you can add several types of content to it:

  • Interactively typed text

  • The contents of an external file

  • A combination of typed text and report fields

  • A combination of report fields

Figure 3.4 shows a combination of typed text and a report field. Here, we added a text field to the report, inserted the text “Printed: ”, including the blank space after the colon, into the text object, and then dragged and dropped the special field PrintDate into the text object. The result is a text string, followed by a space, and then the print date all being treated as a single object. Whenever a database field is added to a text object, its field name is enclosed by a set of parentheses to signal that this is no longer a direct field on the report but rather part of another object.


Figure 3.4. Text objects

The benefit to creating text object combinations is that you can treat a set of objects as a single object for formatting purposes. Text objects can be added to any section in a report.

Warning 

Text objects are limited to a size of 32K.

The Format Editor

The Format Editor, shown in Figure 3.5, is used to change the appearance, including color, of an object in a report. There are two basic ways to open the Format Editor after selecting an object: Choose Format > Format Field or right-click and select the Format Field menu option.

Tip 

Whenever you’re trying to locate an option for an object, try right-clicking after selecting it to see if there is a shortcut menu.

The tabs on the Format Editor vary based on the type of data contained in the field. The field being formatted here is the Report Title mentioned in the first section, so it is a text field and the tabs visible are specific to working with character data. We’ll explore these tabs first and then describe tabs you will encounter with other data types.

click to expand
Figure 3.5. Format Editor - Common tab

Formatting Text Objects

The Format Editor is used to make text information look good on a report. You do this with the use of color, font type and size, and other visual effects. The Sample area at the bottom of the Format Editor gives you a visual idea of how the object will look once it is displayed. The tabs described here are visible in Figure 3.5.

Common

The formatting options found on the Common tab are there for one of two reasons: Either they are frequently used and made it to the Common tab for ease of use, or they don’t quite fit into the categories defined by the rest of the tabs so the Common tab becomes the catchall. Either way, this is a good starting point.

Object Name One of the new features in Crystal Reports 9 is the ability to associate an object name to a text object. Here, ReportTitle1 is the programmatic name used to identify the text object. The use of an object name makes it easier to manipulate the object programmatically and to use it in drop-down box choices throughout Crystal Reports.

CSS Class Name Another new feature in version 9 is the ability to use cascading style sheets (CSS) by associating an object with a CSS class name. Cascading style sheets are rules used with HTML and web browsers to add formatting information (color, font type, font size, etc.) to web pages. If your Crystal Report will be used on the Web as part of a website, the use of style sheets lets you make use of the web page’s styling features so that it appears more closely integrated with the rest of the site.

Read-only The check box option to enable or disable Read-only mode for the object prevents you from accidentally changing format options later on. When Read-only is enabled, all other options in the Format Editor are grayed out and cannot be changed. This option is not related to a user’s ability to change a value on a report if they receive it in an editable format, for instance, as a Microsoft Word document.

Suppress You will have many occasions where you’ll want to add a field to a report but not display it. Instead, it may be used for sorting or grouping or as part of a combination of other fields. The Suppress check box hides a field value from view but leaves it available in Design mode.

Lock Position And Size The option to lock the position and size of an object prevents you from accidentally moving an object. This is great option to turn on after you have the object placed exactly where you want it.

Horizontal Alignment The Horizontal Alignment option provides choices to align left, centered, right, justified, or use the default identified for this type of data. Default settings for data types are globally set using the menu sequence File > Options and choosing the Fields tab. It is important to remember that the data values are being aligned within the dimensions of the object in the report. For instance, referring back to the Report Title placeholder shown in Figure 3.2, the ruler at the top of the screen shows that the text object is three inches wide. Using the Horizontal Alignment option and choosing Left moves the value all the way to the left side of the three-inch area. Likewise, if you chose Right alignment, the text would appear right-aligned at the three-inch mark. So, before using the Horizontal Alignment option, stretch or shrink the object to the size you want and then choose an alignment style.

Keep Object Together When a report is viewed or printed, the values of an object may span more than one page. If an object is small enough to print on one page, selecting this option will prevent the values from starting on one page and finishing on another page. The object will be forced to a new page so that it appears on a single page. If the object is too large to fit on a single page, this option has no effect.

Close Border On Page Break Border boxes can be placed around objects. If the object doesn’t fit on a single page, this option controls whether the border appears with the top and sides on one page and the bottom and sides on the second page, or whether each piece of the object is surrounded by a complete rectangle border.

Can Grow When a field or text object is placed in a report, it is positioned with a default size. The data value in the field or text object may be shorter or longer than the object size. Crystal’s default behavior to handle this is to display only as much of the value as can be seen in the default object size. You have two options for changing this behavior: preview the report and resize the object so that it displays contents in their entirety or enable the Can Grow option. With the latter option activated, the size of an object can grow vertically (lengthwise) to accommodate the object contents. You can specify a maximum number of lines you want the contents to grow to before being truncated or leave the setting at 0 to let the field grow to the size of the contents. The Can Grow option is especially useful when working with fields from a database that were defined as variable lengths; for instance, memo fields in Microsoft Access and text fields in Lotus Notes Domino.

Tool Tip Text Any text you type here will appear in Preview mode as black text in a yellow box as you move the mouse over the object in Preview mode. There is no limit to the amount of text you can type in the field, but there is no way to add a carriage return to the tool tip area, so 70 characters is a practical limit since that much text appears on exactly one line.

Text Rotation Your options here are 0, 90, and 270 degrees, so the only way text can’t appear is upside down. Zero degrees is normal left-to-right text; 90 degrees is readable when you tilt your head to the left with the start of the text at the bottom and moving toward the top. If you tilt your head to the right, 270 degrees appears as starting from the top and moving downward. The 90 degree and 270 degree options are often used as column headings if the width of the column heading exceeds the width of the data column.

Suppress If Duplicated When you format field values retrieved from a database, it is common to come across duplicate values in the data. For instance, a field named FavoriteColors might contain 27 instances of red, 41 instances of blue, 12 instances of green, and 26 instances of purple. Activating the option to suppress duplicates would result in values displaying the values red, blue, green, and purple exactly one time each.

Suppress If Embedded Field Blank Lines This option is available only if you are formatting a text object that contains a combination of text and report fields. The effect of the option is to hide any blank lines in a text object if the only value on that line is empty. As an example, you might use this option if you were printing address labels and the address was formatted as a text object in your report. If the address consisted of an AddressLine1 and an AddressLine2, and the AddressLine2 was on its own line but had no value, using this option would prevent the blank line from printing.

Display String You can place any valid formula here to programmatically format an object; formulas are discussed in Chapter 4, “Adding Business Logic with the Formula Workshop.” The buttons labeled “X+2” that appear in various areas in the Format Editor are places where you can write formula code.

Border

Borders are lines drawn around an object. Using the Border tab in the Format Editor, shown in Figure 3.6, you can control the how the border looks.

Line Style Line styles include single, double, dashed, and dotted. Notice that you independently set the left, right, top, and bottom border line styles.

Tight Horizontal Enabling the Tight Horizontal option automatically sizes the border to the width of the contents of the object. When this option is used in the Details section, which displays records from the data source, the size of the border will vary to match the size of what is stored in the field. Again using the color values of Red, Blue, Green, and Purple, the borders associated with these values would range in size from smallest for the value Red to largest for the value Purple since “Red” is three characters in length while “Purple” is six characters in length; the difference in border sizes is created because of the different character widths of the two text strings.

Drop Shadow The Drop Shadow option adds definition to a border by adding some thickness to it on the right side and the bottom.

Color You can set the border color and the interior background color for a border. A nice formatting technique is to use a dark drop shadow and a light background color. Standard colors are predefined, such as Silver and Maroon, but the entire color spectrum is available using either RGB values or choosing from a color wheel.

click to expand
Figure 3.6. Border options

Font

The Font, Style, Size, and Color can be set on the top portion of the Font tab, shown in Figure 3.7. All available fonts installed on the computer are available as choices through the Font drop-down box, and the one currently being used appears in the box itself. Styles are limited to either Regular or Bold. Font size can be typed directly or chosen from the drop-down list. Font color refers to the color the text will be and should be chosen with the background color in mind; use a color that can be easily read and avoid pastels and lighter colors unless you have a very dark background color. The default font color is black.

click to expand
Figure 3.7. Font options

Effects The Strikeout option draws a line through the contents of the object, while Underline draws a line beneath an object.

Spacing When you choose a font size, it has a default point value used to separate one character from the next. For instance, a 12-point font separates its characters by exactly 12 points. The measurement is taken from the beginning of one character to the beginning of the next character. You can change this default spacing by typing a different number to tell Crystal exactly how many points apart to space each character. Choosing a smaller number will have the appearance of moving the characters closer together, while choosing a larger number will spread the characters out. The font size itself remains the same and controls the height of the characters.

Notice the Sample area at the bottom of Figure 3.7. It appears that the font size selected may have the affect of cutting off part of the object contents. You should take care to size the object back in Design layout mode after changing font formatting to ensure that the contents display correctly. In Figure 3.8, which shows the Preview mode for the Report Title object, the text object needs to be resized so that the full height of the contents can be displayed.


Figure 3.8. Font problem

Warning 

Crystal Reports will not automatically resize an object to accommodate font changes.

Paragraph

Large text objects and database fields that contain varying-length data need to be formatted so that the text will fit it into the report in an eye-pleasing way. For instance, you might format a text object like a newspaper column and place it alongside the right or left border in a report. The Paragraph tab of the Format Editor, shown in Figure 3.9, lets you specify the indentation, spacing, reading order, and text interpretation methods for the contents of an object. The presence of a carriage return line feed character (a hard return) determines when one paragraph ends and a new one begins.

click to expand
Figure 3.9. Paragaph options

Indentations The options for First Line, Left, and Right specify the number of inches text should be indented from the borders of the object. The first line is often indented more than other lines to help it stand out.

Line Spacing Line Spacing is the space placed vertically between each line of text. There are two options: Exact and Multiple. Choosing Exact lets you specify the exact number of points to leave between two lines. When you select Multiple, the base number involved in the multiplication is the font size. So if a 12-point font size was in effect, a multiple of 1 would be 12-point vertical spacing between lines, while a multiple of 2 would be 24-point vertical spacing, and so on.

Reading Order Reading Order is specified as Left To Right, as with the English language, or Right To Left.

Text Interpretation Most text typed directly into a Crystal Report or retrieved from a data source is typed or stored as plain text, meaning text without any formatting attributes associated with it. Some text, however, is already preformatted and needs to be treated differently. You can change how Crystal Reports interprets text by selecting None for plain text, RTF Text for data stored in rich text format, or HTML Text for text stored with HTML tags and ready for display in a browser.

When choosing HTML tags, only a subset of the entire set of tagged language statements is supported. While the list of supported tags includes those that are the most important and most often used, be sure to check the help file to see if the ones in your text field are valid in Crystal Reports.

Hyperlink

Hyperlinks are clickable links that move you to another part of the current report or to a destination outside the current report. The Hyperlink tab in the Format Editor is used to set the destination for a hyperlink. This topic is discussed fully in the “Creating Hyperlinks” section of this chapter.

Formatting Non-Text Data Types

In addition to text objects and text fields, there can be many other data types in a Crystal Report. The Format Editor is still the centralized place to format the object, and in addition to many of the tabs found with text objects, non-text objects have formatting options specific to the data type or object type. Each new data or object type has its own tab in the Format Editor, which is visible only if the object being formatted is of that data type. For instance, if you’re formatting a Boolean field, you’ll see a Boolean tab but not a Number tab.

Boolean Data

Boolean data is a data type that says a value is either True or False. There are many ways to represent these two different states in stored data, and no two products or data sources are guaranteed to store them the same way. Boolean values can be stored as any of the following:

  • True or False

  • T or F

  • Yes or No

  • Y or N

  • 1 or 0

Use the Boolean tab in the Format Editor, shown in Figure 3.10, to choose how the values will display in your report regardless of how they are stored in the data source.

Date and Time Data

Crystal provides an enormous number of options for formatting date and time data. The standard set of date options, shown in Figure 3.11, provides a long list of easy-to-use styles for setting the year, month, and day formats.

click to expand
Figure 3.10. Formatting Boolean data

click to expand
Figure 3.11. Standard date formatting

If the style you need isn’t on the list of standard styles, click the Customize button to display the Custom Style dialog for date data, shown in Figure 3.12. As you can see, there is quite a lot going on in this settings window. Options on Date/Time fields include all possible date options as well as time options, letting you fine-tune year, month, and day formats on one tab and time specifications on a separate tab. In addition, you can format dates so that they appear within square brackets or parentheses using the Encl (enclosure) setting located in the Day Of Week section of the dialog.

click to expand
Figure 3.12. Custom date formatting

Time formatting also has a standard list of styles that let you set the hour, minute, and second components and whether the a.m. and p.m. values should display. These options are shown in Figure 3.13.

In addition to the standard Style list for time, clicking the Customize button displays the Custom Style window for time, shown in Figure 3.14. Here you can set a 12 hour or 24 hour clock, select whether to use one or two digits for the hour, minute, and time components, and also choose a separator character.

click to expand
Figure 3.13. Standard time formatting

click to expand
Figure 3.14. Custom time formatting

Number Data

Numeric data can be formatted in many styles, as shown in Figure 3.15. The choices in the Style list determine how the numeric values in your report display. The two things that change are whether a minus sign or a set of parentheses will be used for values less than zero and how many decimal places should be used. Beyond these two options, everything else is a customized number style.

click to expand
Figure 3.15. Standard number formatting

Choosing the Display Currency Symbol check box shown in Figure 3.15 automatically switches you into Custom Style mode. You can also choose Custom Style directly from the Style list. The Custom Style dialog for numbers is shown in Figure 3.16.

click to expand
Figure 3.16. Custom number formatting

The Use Accounting Format option sets a negative symbol based on your operating system’s settings, displays a dash for data values that are zero, and positions the currency symbol to the left of the data value. Enabling this option changes the values in the bottom half of the dialog; likewise, changing a setting on the bottom to a value that doesn’t match the accounting settings disables the Use Accounting Format option.

If you opt not to use the accounting format, you have granular control over how currency values appear in a report. You can do all of the following to your currency data:

  • Specify the number of decimal places.

  • Round values to the nearest whole number, tenth, hundredth, and so on.

  • Display negative values with a minus sign or parentheses.

  • Allow field clipping to truncate large numeric values.

  • Specify a decimal separator character.

  • Choose whether to display a thousands separator, and if so, what character it should be.

  • Include leading zeros for data values.

  • Substitute a hyphen for a zero data value.

On the Currency Symbol tab, visible but not displayed in Figure 3.16, you can specify the following display options:

  • Show the currency symbol in a fixed position for all data values.

  • Show the currency symbol as close to the data value as possible (float).

  • Show only one currency symbol per page with the first number on the page.

  • Show the currency symbol on the left or on the right.

Formatting Visual Objects

Visual objects can be added to a report and include boxes, lines, and pictures. Once they exist in the report and are selected as the active object, you can format these object types with the Format Editor.

Working with Boxes

You can draw boxes around text objects and field objects by choosing Insert > Box. A pencil mouse pointer appears and assists you in drawing a rectangle of any size. With the object selected, right-click and select Format Box to open the Format Editor or choose Format > Format Box from the menu bar. This displays the Box tab of the Format Editor, as shown in Figure 3.17.


Figure 3.17. Formatting boxes

You can vary the style, width, and color of a box border as well as add a drop shadow. The width can be set for only the single line style, not dotted or dashed. Enabling the Fill Color option displays the standard predefined color choices and the RGB (red, green, blue) color wheel.

Choosing to close the border on page breaks guarantees that your box will have four sides even if the contents get split between pages; otherwise, the box will have a left, right, and top on one page and a left, right, and bottom on the next page. The Suppress option hides a box from view. The Read-only option disables all other formatting, and the Lock Position And Size option prevents the box from accidentally being moved during your design work.

The Extend To Bottom Of Section When Printing option is specific to the box object, and it allows the box to stretch to the end of a section. When used in the Details section around a field value, this option can be used to make check boxes in your report or to give you a writing area associated with a field value. Figure 3.18 shows how this option looks around the ResortCode field in our report.

Working with Lines

A line is added to a report by choosing Insert > Line. A pencil mouse pointer appears, and it helps you draw a straight line up, down, to the left, or to the right. Once you’ve positioned a line in the report, the Format Editor lets you change the style, width, and color of the line, as shown in Figure 3.19. The Format Editor is displayed by selecting the object and then either choosing Format > Format Line or right-clicking and choosing the Format Line option.

Tip 

To show a double line below a field, add a border instead of a line, and set the top, left, and right of the border to “None” while setting the bottom of the border to “Double.”

For line styles, you can choose from Single, Dashed, and Dotted. There is no option for a double line style as there is with formatting a border. The width can range from less than .5 points (known as a hairline) up to 3.5 points. You choose the width by clicking the desired button; the point size of the selected button appears to the right of the row of buttons. The Color drop-down list contains a set of predefined colors and also lets you specify RGB values.

click to expand
Figure 3.18. Extending boxes


Figure 3.19. Formatting lines

The check box options to suppress a line, mark it as read-only, and lock its position and size behave in the same manner as these same options described for text objects earlier.

The Move To Bottom Of Section When Printing option is specific to the line object. Enabling this option sizes the line according to the size of the section. This option is useful for creating a line in a section with a varying-length field (e.g., a memo field) so that the line is the same length as the data. When this option is disabled, which is the default, the line remains a constant size in each section.

Working with Pictures

A picture is added as an OLE object (discussed later in the section “Working with OLE”) to a report. You have some limited formatting control over the object once it exists in your report; however, you should do any fine-tuning to the graphic in a graphics software package and not in Crystal Reports. With the picture selected, choose Format > Graphic or right-click and choose Format Graphic to display the Format Editor, which now includes a Picture tab, as shown in Figure 3.20.

click to expand
Figure 3.20. Formatting pictures

There are three things you can do to format a picture:

  • Crop it.

  • Scale it.

  • Size it.

Cropping a picture lets you choose a portion of the image to display. You can remove parts of the picture in rectangular fashion, cropping from the left, right, top, or bottom.

Scaling a picture geometrically resizes the image to display the whole picture in a fraction of its original size. To shrink the picture in half, you would set the Width and Height values to 50%. You can scale the picture in one dimension only, such as by height, if you need to, but the results will resemble the Hall of Mirrors at a carnival, so be careful. You can also size the picture exactly using inch measurements. The Size measurements affect the Scaling measurements and vice versa.

Tip 

If you change your mind at any point, click the Reset button to restore the picture settings to their original values.

Pictures often have hyperlinks associated with them, so now’s a good time to discuss how to create hyperlinks.

Use of content on this site is expressly subject to the restrictions set forth in the Membership Agreement
 
Conello © 2000-2003     Feedback


Mastering Crystal Reports 9
Mastering Crystal Reports 9
ISBN: 0782141730
EAN: 2147483647
Year: 2005
Pages: 217

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