问题
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.
- Use from SQLCLR to create a Rendered HTML PNG and sendit toyour reports
- use HTMLDecoder to decode html code block to Rendered HTML. this script can find at :
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)
- 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