Render html code in sql server client report (rdlc)

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-22 17:58:11

问题


I am using the asp.net web application and microsoft visual studio reportviewer control and rdlc for creating a report ( not using sql server reporting). I used the Product table to view the result. It has five fields and I display all the itemsin the report. One field is Description and it store the html code as the value(eg:

<div><ul><li>a</li><li>b</li></ul><b>aaaa</b></div>

). I want to disply the output of this html code in my report's description field. But in my report, it shows the html value that I stored in my table (:

<div><ul><li>a</li><li>b</li></ul><b>aaaa</b></div>

). How can I render the html in my report. Please give me a solution.


回答1:


See Rendering HTML in Reporting Services Text Boxes in SQL Server 2008

I've not tried it and may not apply to rdlc etc, so YMMV




回答2:


Dear Masoud as GBN mentioned in his link, by default SSRS doesn't provide any solution to Render HTMl from HTML Code block. but you can use one these solution to render HTML in SSRS reports.

  1. Use from SQLCLR to create a Rendered HTML PNG and sendit toyour reports
  2. use HTMLDecoder to decode html code block to Rendered HTML. this script can find at :
  3. You can Use below code block to convert simple html code to Rendered HTML

    Public Shared Function ConvertRtfToText(ByVal input As String) As String
         Dim returnValue As String = String.Empty
            Using converter As New System.Windows.Forms.RichTextBox()
                  converter.Rtf = input
                  returnValue = converter.Text
            End Using
         Return returnValue
    End Function
    

You can also use this code block

 Function RtfToText(ByVal value As String) As String
   If value.Contains("rtf1") Then
       Return System.Text.RegularExpressions.Regex.Replace(System.Text.RegularExpressions.Regex.Replace(System.Text.RegularExpressions.Regex.Replace(System.Text.RegularExpressions.Regex.Replace(value,"[\n\r\f]", ""), "({\\)(.+?)(})|(\\)(.+?)(\b)", ""), "{", ""), "}", "").Trim()
   End If
   Return value
   End Function

you can finally call these code onyour textbox with

  =Code.RtfToText(Fields!HTMLCode.Value)
  1. You can also use some utility like http://pebblereports.com/reportingservicesutilities/ to display Rendered HTML in SSRS


来源:https://stackoverflow.com/questions/2172105/render-html-code-in-sql-server-client-report-rdlc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!