Site icon Paul Turley's SQL Server BI Blog

Rich Embedded Text Formatting in Reports

I’ve recently come to realize what a truly remarkable feature it is to be able to format report text using simple HTML tags.  This capability was added to Reporting Services in SQL Server 2008.  Prior to this, all of the text in a textbox could be formatted with a font size, bold, italic or what not – but these properties were applied to all of the text in the textbox.  Now, the contents of any textbox can be either behave as it used to or the contents of a textbox can be converted to a placeholder for rich-formatted text.

Working on a client’s project, several reports need to be localized.  It’s not so much that reports need to show information in different languages but elements like the company subsidiary name, division and contact information are different in various regions of the world where this company conducts business.  On contracts and invoices, the legal terms and disclaimers are different because of regional laws and different business practices.  In the past, they have created different reports for each region – which has been a high cost maintenance issue.

I’ve created only one version of each report to be localized using a Region parameter.  There’s one Invoice, Quote report and Job Information sheet report.  I created a table in the database containing fields to store the report name, the name of the text block, the region and the HTML formatted text for the region-specific text block.  In the report, I use a simple dataset with a query that returns the text for that report using these fields and the parameterized region in the WHERE clause.  It’s a simple but elegant solution to an otherwise complex problem.

Reporting Services supports a short list of simple HTML tags for embedded or data bound rich text.  These include:

· Hyperlinks: <A href>

· Fonts: <FONT>

· Header, style and block elements: <H{n}>, <DIV>, <SPAN>,<P>, <DIV>, <LI>, <HN>

· Text format: <B>, <I>, <U>, <S>

· List handling: <OL>, <UL>, <LI>

Detailed instructions for this feature are available in the online MSDN library.

What?  No CSS Support?

One of the constants in the universe is that when a new feature is added to a software application, a lot of users and customers will immediately complain and demand that the feature be improved to meet some greater need.  To this I say quit your whining and be grateful for what you you have.  This is what my parents used to say before they shared stories about walking up hill in the snow both ways to and from school.  Many reporting products don’t have anything close to this.  When this feature was added, the product team made it a point to keep this feature simple while giving us some very useful capabilities.  

I recently needed to include a rich-formatted legal disclaimer as an ordered number list with multiple levels of subordinate numbered levels.  I know that as a web designer, this kind of thing can be managed in greater detail using CSS styles which are not supported by SSRS.  The trick in my case was to get the right combination of nested <LI> and <OL> tags.  The following combination did the trick:

<ol>

<li>First item</li>

<li>Second item

<ol>

<li>First child of second item</li>

<li>Second child of second item</li>

</ol>

</li>

<li>Third item</li>

</ol>

…which produces:

1. First item

2. Second item

    i.    First child of Second item

    ii.   Second child of second item

3. Third item

Why doesn’t this feature support Cascading Style Sheets?  Simple… the embedded HTML is not ever parsed by the web browser.  These tags are read by the core report rendering engine which translates the inline tags to static text elements and then outputs the appropriate content to the appropriate rendering extension.  This means that, like most report features, the rich formatted text is going to work the same way in reports rendered to PDF, Excel, Word, an image, print or any web browser because the report content is rendered on the server, rather than in a web browser.

Thanks to Andrew Karcher, Thiago Silva and Robert Bruckner for their contributions.

Exit mobile version