none
rendering html string from database in word automation RRS feed

  • Question

  • Hi,

    Scenario:

    I am working with a desktop application that gets a database record/list item from a SharePoint 2007 list/table. One of these columns contains a text with html tags. This information is to be presented as a report (a DOC file) to another department/customer.

    The problem:

    I use Bookmarks to to insert this text into the word document using. Every thing works fine EXCEPT, the column containing html tags is showed AS IT IS, which means in the report, I am getting HTML tags instead of getting formatted.

    In simple words, how to get rid of these tags, and represent the data in the form as it will be shown on the web page.

    Thank you in advance.
    Harry

    Thursday, December 9, 2010 3:19 PM

Answers

  • To do that, I think you will have to use the Win32 clipboard API to copy the text string that you have (i.e. that contains HTML tags) to the Clipboard as "HTML Format" text. Then you should be able to use Selection.Paste or perhaps another Paste option in the Word object model to paste the text in a way that inserts the formatting.

    The following MS Knowledgebase article describes how to do that in VB - AFAICS, the sample code works OK in Word VBA, but you need to play around with it a bit to fit in with your requirement.

    http://support.microsoft.com/kb/274326

    The thing that I couldn't get right until I found the article was that you had to add some header info. to the HTML before putting it on the clipboard. Previously, I'd done the same with RTF and you just seemed to have to add the RTF code.

     


    Peter Jamieson
    • Marked as answer by Bessie Zhao Thursday, December 16, 2010 9:10 AM
    Thursday, December 9, 2010 9:15 PM

All replies

  • To do that, I think you will have to use the Win32 clipboard API to copy the text string that you have (i.e. that contains HTML tags) to the Clipboard as "HTML Format" text. Then you should be able to use Selection.Paste or perhaps another Paste option in the Word object model to paste the text in a way that inserts the formatting.

    The following MS Knowledgebase article describes how to do that in VB - AFAICS, the sample code works OK in Word VBA, but you need to play around with it a bit to fit in with your requirement.

    http://support.microsoft.com/kb/274326

    The thing that I couldn't get right until I found the article was that you had to add some header info. to the HTML before putting it on the clipboard. Previously, I'd done the same with RTF and you just seemed to have to add the RTF code.

     


    Peter Jamieson
    • Marked as answer by Bessie Zhao Thursday, December 16, 2010 9:10 AM
    Thursday, December 9, 2010 9:15 PM
  • Peter,

    Thank you. I shall try it.

    Regards,

    Harry

    Monday, December 13, 2010 10:58 AM