5
votes

I am using SSRS 2012. We have a placeholder that contains an expression that dynamically grabs a column in our database which stores html. SSRS unfortunately does not support the CSS style background-color, which we use to display highlighted text.

For example, given the HTML below

<span style="background-color: #ffff00;">highlighted text</span>

We would like to show the text "highlighted text" with a yellow background color.

Is there a way to add custom code to SSRS that allows us to replace a span tag with some type of SSRS inline background color markup, such as [background-color:yellow]highlighted text[/background-color]

2
What ssrs control is your data being displayed in?dotNetE
We are using a tablix which contains one textboxfar_loner
Did you try the BackgroundColor Property?MarlonRibunal
@MarlonRibunal Unfortunately the BackgroundColor Property won't work because I need to only highlight one or two words in a sentence, such as this is a sentenced with highlight text. In the previous case only the word "highlight" would show up as highlighted.far_loner

2 Answers

0
votes

You can just include the tags in the field data and set the textbox to interpret HTML tags. SSRS only recognizes a subset of tags, but I think is, and definitely is. "SQL Chick" has an article on it here. Of course, your report query has to be smart enough to know where to put the highlight tags.

0
votes

I do not believe it can be done. I have encounterd the same problem. SSRS will recognize fore color. It will not recognize background-color or even the tag level bgcolor

i ran a quick test to see if there was anything i can do in ssrs to get around the limitations. It appears that SSRS actively scrapes the content and the styling and then applies it as it wants.

Here you see a quick report I made. I entered some simple HTML into a table and then tried to display that as HTML. You can see the raw HTML and the resulting SSRS rendering. The first column is Len(rawHTML). There was a question as to whether SSRS or SQL was truncating the rawHTML. The column is currently defined as nVarchar(8000).

SSRS report showing raw HTML stored in DB and resulting placeholder w/ DISPLAY AS HTML = TRUE

Here is a peek under the covers. This is CHROME DevTool showing the rendered HTML for the NOT UNDERLINED tag from above. You can see that none of the actual HTML is passed through.

CHROME DevTool showing what SSRS actually renders when you look at the report in a browser.

MS seems to have very strong feelings about not allowing HTML injection or JS injection into reports. ( I have tried everything I can think of to get a report to import a D3 image from a webpage, I have not been able to do it)

I can begrudgingly give to MS that allowing JS injection would lead to an avalanche of error reports. To a lesser degree, i can see HTML insertion being a potentional problem.

Unfortunately, this leads to their 'scrape and emulate' approach. The support for HTML formatting seems to be pretty shallow.

For those interested, here is the version information for my SSRS. SQL Server is 2019 Enterprise.

enter image description here