Let’s say you want to mix formats of a single textbox on a SQL Server Reporting Services report, as follows:
Different formats could include mixing font sizes, colors, and other things like bold and italics within one textbox. The easiest way to handle different formatting is to split it into 2 textboxes. However, you may have a need to stay within one textbox depending on the string that needs to be concatenated, or to avoid alignment issues with other textboxes. Within one textbox, I’ve found 3 ways to format specific text, numbers, fields, or expressions:
1. Selected Text Properties
2. Placeholder Properties and Text Properties Panes
3. HTML Tags (which also involves Placeholder Properties)
The remainder of this entry discusses each of the 3 methods. This technique applies only to SSRS 2008, R2, and Report Builder 3.0. SSRS 2008 R2 is used for the examples shown.
Selected Text Properties
This is the most straightforward technique, and should be familiar as it’s used throughout many Microsoft applications. After you highlight a portion of the textbox, you may use the toolbar or the Properties Pane which will have “Selected Text” as the object name. The key to making this work is you need a simple expression, rather than a complex expression in the design view (i.e., make sure the design view does not show just <Expr> for the entire textbox - within part of it is okay though - see "A Word About <Expr>" toward the end of this entry).
Note that after mixed formatting is applied, if you right-click the textbox, the Expressions option is no longer available:
Next let’s get into the more interesting capabilities.
Placeholders were introduced in SSRS 2008 to accomplish the very goal we have. As with the previous technique, this relies on a simple expression, rather than a complex expression in the design view (i.e., make sure the design view does not show just <Expr> for the entire textbox - within part of it is okay though - see "A Word About <Expr>" toward the end of this entry). A simple expression will show our sample field as [@ParamQtrEnd] instead of =Parameters!ParamQtrEnd.Value. More information on simple versus complex expressions can be found in the Understanding Simple and Complex Expressions article on MSDN.
Just where are Placeholder Properties? In the design GUI, the Placeholder Properties are not available through the right-click menu for the textbox. You need to click twice inside a textbox (i.e., activate your cursor within the textbox) and then right-click to see this menu item.
- If there’s nothing in the textbox yet: you’ll see Create Placeholder in the menu.
- If you highlight a field: you’ll see Placeholder Properties in the menu.
- If you highlight text: you’ll see Text Properties in the menu.
The Placeholder Properties pane offers different tooltip, formatting, and action for the text selected in the textbox. The Text Properties pane offers the same options, with one exception: it doesn’t have the Number page of options since it’s only formatting text.
Use the various options to specify formatting desired for the selected portion of the textbox. You may use several combinations of Placeholder Properties and Text Properties within one single textbox. Valentino Vranken has a very nice discussion on his blog entry: The Power of the Placeholder.
This option delivers a bit more flexibility, particularly if you have a complex expression in your textbox. Using HTML tags will work if you have a complex expression (i.e., <Expr> shown in the design view).
First, you do need to define Placeholder Properties on the Expression:
Within the Placeholder Properties, change the default Markup type to be “HTML – Interpret HTML tags as styles.” If you forget to change this radio button, then the html tags will be rendered as literal text.
Then within your expression, insert the HTML tags as needed.
Only a subset of HTML tags are supported within SSRS, such as bold, italics, and underline. The MSDN page on Formatting Text and Importing HTML specifies the valid HTML tags you may use within an SSRS textbox. If you use an HTML tag that isn’t supported in SSRS, it will be ignored.
As a sidenote, using HTML tags within a simple expression will work as well:
However, in a real situation, I would reserve using HTML tags to situations when I have a complex expression. With a simple expression, I’d opt to keep the formatting options simpler.
A Word About <Expr>
Above I stated a couple of times that you can't have just <Expr> for the entire textbox and have the placeholder technique work, except for the HTML tags method. However, an <Expr> inside part of the textbox will still work. An example to illustrate:
What won't support partial formatting (except using HTML tags):
Will support partial formatting (using any of the methods discussed above):
Reporting Services 2008 introduced enhanced rich text functionality to permit mixed formatting, or even mixed tooltips & actions, within a single textbox. There’s several ways mixed formatting can be accomplished. Placeholder Properties can be used with the GUI formatting options, or with a subset of HTML tags. The GUI formatting options work best with simple expressions, whereas the HTML options provide a lot of flexibility for complex expressions.