Answered by:
SSRS VB Code to remove certain formatting

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:
- 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 - Use the expression below to replace the original field with HTML Markup type:
=Code.RemoveHtmlBold(Fields!field_name.Value)
Hope this helps.Thanks,
Katherine XiongKatherine Xiong
TechNet Community Support- Proposed as answer by Chongtham Rajen Singh Friday, December 20, 2013 7:58 AM
- Marked as answer by Katherine Xiong Thursday, December 26, 2013 3:24 AM
Friday, December 20, 2013 5:10 AM - Copy the custom code below and paste it to your report. (Right-click report>Report Properties>Code)
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:
- 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 - Use the expression below to replace the original field with HTML Markup type:
=Code.RemoveHtmlBold(Fields!field_name.Value)
Hope this helps.Thanks,
Katherine XiongKatherine Xiong
TechNet Community Support- Proposed as answer by Chongtham Rajen Singh Friday, December 20, 2013 7:58 AM
- Marked as answer by Katherine Xiong Thursday, December 26, 2013 3:24 AM
Friday, December 20, 2013 5:10 AM - Copy the custom code below and paste it to your report. (Right-click report>Report Properties>Code)
-
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