Displaying RTF or HTML in a report?

  • I am trying to display text that has been stored in RTF format, in a SQL Server database, within a report. The problem is that when displayed it includes all associated formatting notation ie:

    {\rtf1\ansi\deff0\deftab720\ql\plain\f3\fs16 some text here \par }

    Anyone come across the problem, is there away to display the text as it might appear in eg wordpad? Or even a way to just strip out the required text part? ie I just want to see: some text here

    The same problem occurs with HTML stored in a database

    ie the report will have <b>bold</b> and not bold - I guess this is to avoid the browser rendering html accidently, but what if this is what you want?!

    Any ideas?

    Thanks.

  • you should be able to use regualr expressions to strip out either rtf or html;

    you can do it within an app or client side in vb or .net, but for SQL 2000 you have to use an extended stored procedure. regardless of where you do it, the regular expressions are still the same:

     

    'vb6 example:

    Private Shared regexObject As Regex

    Shared Sub New()

    regexObject = New Regex("({\\)(.+?)(})|(\\)(.+?)(\b)")

    End Sub

    Public Shared Function RemoveTags(ByVal rtfText As String) As String

    Dim cleaned As String = regexObject.Replace(rtfText, "")

    Return cleaned.Replace("}", "")

    End Function

    '==========================================

    '.Net Example

    using System.Text.RegularExpressions;

    public string Strip(string text)

    {

        return Regex.Replace(text, @”<(.|\n)*?>”, string.Empty);

    }

    to use regualr expressions on SQL server 2000:

     

    xp_regex: Regular Expressions in SQL Server 2000

    By Dan Farino

    http://www.codeproject.com/managedcpp/xpregex.asp

     

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • interesting, will look into that, thanks very much!  However, seems quite fiddly but I guess its gonna have to be...

  • Thanks for this. I'm new to this stuff and been looking for a way of stripping the RTF tag from records created by my 3rd party software in SQL 2000. Searching the web over the last few days I found a number of people facing the same problem but no solutions that I could impliment directly within SQL 2000. Having installed xp_regex, I created a function:

    exec master.dbo.xp_regex_replace @MyRTFText, '({\\)(.+?)(})|(\\)(.+?)(\b)|}|\s?', '', @MyText output

    (I also needed to strip out an extra white space from the beginning of the string)

    I have now been able to call this function from all my stored procedures where the data is in an RTF wrapper.

    Thanks once again.

      

  • I know how to strip html (or rtf) markup but is there a way to display the formatted html in the report? I am reporting over data in a Sharepoint list and some of the fields contain rich text which is then formatted as html and I would like to display it formatted as the user intended.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply