Pages

Monday, April 12, 2010

Rich text in SSRS 2008

One of the most irritating and common requirements that I faced as a developer in SSRS 2005 was when I had to colour words in the same line differently. Even though SSRS 2005 didn’t provide an inbuilt feature to do this, this could always be done by placing the words in different textboxes.

Suppose I had a title as

Category = Accessories and Order Count = 19523

where Accessories and 19523 are retrieved from the dataset, and if I just wanted them in a single colour, I could write the below expression in a textbox.

=”Category = “+Fields!Category.Value+” and Order Count = “+Fields!Order_Count.Value

The hassle was when the customer gave the requirement that the values should be in a different colour and in bold. Now for this, we need to break the expression into different parts such that only consecutive words of the same colour appear in one textbox. Hence, the above expression had to be broken down into 4 textboxes:-

1) Category =

2) Fields!Category.Value

3) and Order Count =

4) Fields!Order_Count.Value

and then each textbox could be given it’s own property.

simulating rich text in SSRS 2005

This would prove to be very annoying for the developers especially if the sentence was a very long one which had alternating colours in between.

Preview of rich text in SSRS 2005

Also, unless you painstakingly spend hours in it, the spacing would not be 100% accurate. For eg, if you see in the above image, you can notice that spacing between the words is not uniform

But with the advent of SSRS 2008, this issue is a matter of the past. Now you can directly type in your sentence and/or drag and drop the fields from the dataset or the report parameters. To change the properties of the required text, just highlight the part and then press F4 to view the property panel of the selected text.

Rich text in SSRS 2008

In the example above, I have highlighted the [Category] text. Notice how the property panel displays Selected Text, and not the name of the textbox. Now you can change the properties as you like be it the colour, indentation, font, etc. Another thing to notice is that instead of displaying <<Expr>>, we can actually see the words and the Field names have a placeholder. Eg, for Fields!category.Value, we actually see [Category]. Also see below how neat the result looks compared to what we had in 2005.

Preview of rich text in SSRS 2008

This can be extended to objects like tables and matrixes also. In SSRS 2005, if it was required to have a column partially bold or coloured, we had to make different textboxes and then enclose them within a rectangle. Then the rectangle could be used in the matrix.

Table in Design mode - SSRS 2005  Table in preview mode - SSRS 2005

In SSRS 2008, you can just select the required text and edit as mentioned in the previous section.

Matrix in Design Mode - SSRS 2008 Table in preview mode - SSRS 2008

It is small features like this which makes me an ardent fan of SSRS 2008.

6 comments:

  1. Hi Jason, is this possible with multiple datasets? If so, how do you specify the dataset?

    ReplyDelete
  2. Sorry, just figured it out right after I posted this comment. For anyone interested, right-click on the text field, click on create placeholder, go to General > Value and select the fx button.

    ReplyDelete
  3. Thanks Jason, this was very helpful! Prevented me from punching through my monitor at work today. :)

    ReplyDelete
  4. In 2005 a workaround would be to set the textbox width and position dynamically using an expression based on the length of the value it contained. But agreed this is ugly and 2008 is much better

    ReplyDelete
  5. @Karl : Hmmm, as far as I remember 2005, textbox width and position could not be set dynamically in SSRS 2005, which is why this approach was taken.

    ReplyDelete
  6. I found a Solution that's most simplier.

    Right click on the Cell and select expression.
    Type your expression with HTML BOLD code or Underline.

    Then close the expression editor
    Select the text "express" in you text box and right click on it
    Select placeholder properties and tick "HTML - Interpret tags as..." save and...

    Enjoy with this solution

    Chris
    regard'AT'ttt.ch

    ReplyDelete