📜 ⬆️ ⬇️

We learn MS SQL Server Reporting Services 2008 R2 to show HTML in reports



Problem


I recently encountered the need to show HTML tables stored in a database in a SSRS 2008 R2 report.
And here on the stage extras bring carefully prepared "rakes". The thing is that Report Manager in SSRS 2008 R2 supports only a limited number of HTML tags, and tabular ones are not included.
According to official documentation, only the following tags are supported:

The list of CSS attributes is also heavily trimmed.

After a long search on the Internet, it became clear that none of the options offered by the developer community would suit me.
')

Study


Options offered are as follows:

In one of the discussions, I came across a hint - Javascript on the client side. There was no ready solution.
I started by trying to analyze what code is executed on the client side when displaying a report. I looked into the report code in the browser and found the embedded ReportingServices.js script:
<script language="JScript" src="/Reports_SQLEXPRESS/js/ReportingServices.js" type="text/Javascript"></script> 

The script itself on my server was lying here:
 c:\Program Files\Microsoft SQL Server\MSRS10_50.SQLEXPRESS\Reporting Services\ReportManager\js\ReportingServices.js 

I found a couple of articles on the topic of Javascript injection using this script, but the main problem was that my modifications were performed only once when the first page of the report was displayed, and when going to the next pages, the interface elements were not redrawn (AJAX).
Attempts to gain a deeper understanding of how SSRS works continued by studying the code snippets of the main DLL servers using DevExtras CodeReflect and preparing reports in IE9 developer tool / Opera Dragonfly.
As a result, found the following:
In order to add your handler, you need to create a pageLoad JS function that will be automatically executed when the Load event occurs:
 function pageLoad(sender, args) { //  ,  alert("!"); } 
I insert this construction at the very beginning of the ReportingServices.js script. Works!

Decision


Actually, further the puzzle has already gathered and the following solution has turned out:
  1. Add the following function to the beginning of the % SSRS Install Dir% \ Reporting Services \ ReportManager \ js \ ReportingServices.js script:
     function pageLoad() { var toDecode = document.getElementsByTagName("div"); //   DIV for (var i = 0; i < toDecode.length; ++i){ //  if(toDecode[i].innerHTML.indexOf("HTMLInject:") == 0){ // DIV  ? Decoded = toDecode[i].innerText || toDecode[i].textContent; //  IE, Opera, FF toDecode[i].innerHTML = Decoded.slice(11); //   & TXT --> HTML } } } 

  2. Now, to display the field as HTML, in the properties of the placeholder in the field Value you need to write the following:
     ="HTMLInject:"+Fields!FieldName.Value 
    where FieldName is the name of the dataset field containing HTML.


    In this case, the property “General \ Markup type” of the field itself must be set to the value " None - Plain text only ".

  3. If you need to change the HTML styles, you can make changes to this CSS: % SSRS Install Dir% \ ReportingServices \ ReportManager \ Styles \ ReportingServices.css However, I was lucky and my HTML tables were formatted with classes, which I added to the CSS file.

And now examples


This is the default display of the field ("None - Plain text only"):


So shows the table, if the markup type to put in the "HTML - Interpret HTML tags as styles":

My version:


Pro / contra of such a decision


Advantages:

Disadvantages:

findings


So, with the help of simple devices, you can teach SSRS to show HTML ... But why ?!
Hundreds of posts, from confused to angry, overwhelm the Internet because of such trifles.
Even BIRT has been able to do this for a long time, but the latest version of SSRS2012 is not yet available (pruflink: http://technet.microsoft.com/en-us/library/ff519562.aspx ).
There are thoughts that MS implemented the HTML display in such a limited way so that the security / stability of the reporting system did not suffer, but it seems that all alternative solutions resemble the notorious “trolleybus”.

UPD:
About rendering HTML into a picture - based on this, you can try to develop a Custom report Item.

Source: https://habr.com/ru/post/142597/


All Articles