locked
SSRS VB Code to remove certain formatting RRS feed

  • Question

  • Hi,

    I have inherited a number of SSRS reports which display information entered at source as rich text. The field within SSRS has the Markup type set as HTML. Simple switching this to plain text obvioulsy removes all formatting (not the desired result) - what I'd like is to be able to ignore specific markup, for example if the text is bold/strong or coloured I'd like some code which removes only these tags.

    I guess I'm after a VB function which accepts the text, allows me to set the tag names to strip, and then returns the parsed string.

    Any help with the VB would be greatly appreciated.

    Thanks



    • Edited by _c Wednesday, December 18, 2013 5:00 PM typo
    Wednesday, December 18, 2013 10:39 AM

Answers

  • Hi CDG100,

    Just as you think, we can use custom code (VB) to write functions to remove certain format. The following custom code which I tested is to remove the bold format, please see:

    1. Copy the custom code below and paste it to your report. (Right-click report>Report Properties>Code)
      Public Shared Function RemoveHtmlBold(input As String) As String
              Dim pattern As String = "<h[1-5]>"
              Dim r As New System.Text.RegularExpressions.Regex(pattern)
              Dim result As String = r.Replace(input, "")
              pattern = "</h[1-5]>"
              r = New System.Text.RegularExpressions.Regex(pattern)
              result = r.Replace(result, "")
              Return result
      End Function
    2. Use the expression below to replace the original field with HTML Markup type:
      =Code.RemoveHtmlBold(Fields!field_name.Value)


    Hope this helps.

    Thanks,
    Katherine Xiong


    Katherine Xiong
    TechNet Community Support

    Friday, December 20, 2013 5:10 AM

All replies

  • Hi CDG100,

    Just as you think, we can use custom code (VB) to write functions to remove certain format. The following custom code which I tested is to remove the bold format, please see:

    1. Copy the custom code below and paste it to your report. (Right-click report>Report Properties>Code)
      Public Shared Function RemoveHtmlBold(input As String) As String
              Dim pattern As String = "<h[1-5]>"
              Dim r As New System.Text.RegularExpressions.Regex(pattern)
              Dim result As String = r.Replace(input, "")
              pattern = "</h[1-5]>"
              r = New System.Text.RegularExpressions.Regex(pattern)
              result = r.Replace(result, "")
              Return result
      End Function
    2. Use the expression below to replace the original field with HTML Markup type:
      =Code.RemoveHtmlBold(Fields!field_name.Value)


    Hope this helps.

    Thanks,
    Katherine Xiong


    Katherine Xiong
    TechNet Community Support

    Friday, December 20, 2013 5:10 AM
  • Thank you Katherine. Great.

    Could it be amended slightly to include other tags. i.e. could I pass through <h>, <strong>, <i> to the same function, or would I have to create duplicate functions to cater for individual tags?

    Note - I do not want to remove all HTML formats, just the ones I specify.

    Friday, December 27, 2013 10:17 AM