Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

2.08 Tutorial 2-2. Applying Multiple Formatting Properties

Tutorial 2-2. Applying Multiple Formatting Properties

  1. Add a new text object anywhere on the report and make it tall enough to show a few lines of text. But don’t make it too long.
  2. Enter some text to fill up the text object. Notice how the cursor automatically moves to the next line when it gets to the edge of the box.
  3. Right-click on the text object and select Format Text. Click on the Paragraph tab.
  4. We want the first line to be indented and the margins to be offset from the border of the text object.
  5. Enter 0.25 for the First Line property. Enter 0.05 for both the Left and Right properties.
  6. Click the OK button. Notice how much nicer it looks.
  7. Let’s change some of the formatting within the text. Double-click inside the text object to put it in edit mode. Highlight one of the words and make it bold. Highlight another word and make it underlined. Your paragraph might look similar to mine.


The benefit of learning how to format text objects is that the same formatting options are available for many of the objects on a report. For example, the next section discusses the field object and it can be formatted just like text objects.

Field Objects

The typical field object displays data from a table or a formula. Some other fields in the Field Explorer are formulas, parameters, and special fields. Special fields are discussed later in this chapter and the other fields types are discussed in their appropriate chapters.

The previous tutorials demonstrated how to use different formatting properties within a single text object. Another interesting aspect of the text object is that you can embed field objects within text objects. The benefit is that the spacing between fields is automatically adjusted and extra space is eliminated. Let’s look at an example of an employee’s address where the city, state and zip code are placed next to each other using text objects. Figure 2-13 shows the address fields adjacent to each other in the Details section. Figure 2-14 shows what they look like in Preview mode.



Figure 2-13. Addresses in the designer.


Figure 2-14. Addresses in preview mode.

Notice in the first figure that when the fields are placed next to each other in the Details section that each field has to be large enough to accommodate the maximum amount of characters. If the field is too small then part of the data will be cut off. As you can see in the second figure, using text objects results in the address fields being spaced too far apart.

The way to solve this problem is to embed the fields in a text object. Text objects are flexible because not only can you type text in them, but you can put fields into a text object as well. This squeezes all the fields together so that they are adjacent to each other with no extra space between them. You can also type regular text between the fields and they all fit accordingly. This is useful when writing form letters where there are large paragraphs of standard text and you want to insert a field into certain sections (e.g. the person’s name or something they purchased from you). And lastly, we saw in the previous tutorial that the fields within a text object can each have their own formatting.

When you drag the database field into the text object, the mouse changes to a blinking cursor to show you where the field will be inserted. Look at the next figure to see how a single text object uses all three address fields and inserts a comma after the city. The figure after that shows how much better it looks in Preview mode.



Figure 2-15. Embedded fields in the text object.


Figure 2-16. Embedded fields in preview mode.

A bit of caution should be exercised when embedding database fields into text objects. If this is very large report and the text object is printed repeatedly, this can slow down performance. Instead of embedding fields into the text object, create a formula that concatenates the fields together and returns a single string. This decreases report processing time. The only drawback to using a formula for concatenating fields is that you can’t use the Format toolbar to apply special formatting to individual parts of the string. The entire string is uses the same formatting properties. Luckily, in Chapter 6 you’ll learn a trick that uses HTML to fix this problem.