Search code examples
htmlvb.netwinformsms-wordmailmerge

mail-merge HTML from a database into MS Word


project: Using VB.NET to build a winforms database interface and work-automation app.

I am using this editor for the users to enter their text in the database interface environment that will both load/save/show them what they are working on in the form and also mail-merge into a Word document waiting for the content. I can do the first step and it works well, but how do I get MS Word to recognize HTML as formatting instead of just merging in tags and text all as text?

The tool has two relevant properties: one to get just the text (no markup, i.e. no HTML) and one to get the full markup with HTML. Both of these are in text format (which I use for easy storage in the Database).

ideas/directions I can think of:

1) use the clipboard. I can copy/paste the content straight from the editor window to Word and it works great! But loading from a database is significantly different, even when using the clipboard programatically. (maybe I don't understand how to use the clipboard tools)

2) maybe there is a library or class/function in Word that can understand the HTML as "mergable" content?

thanks!

:-Dan


Solution

  • I ended up using the clipboard to set the text. Here is a code sample that I needed to answer this question.

    Clipboard.SetText(Me._Object.Property, TextDataFormat.Rtf)
    

    I just didn't know how to tell the computer that the content was HTML or RTF etc. It turned out to be simple.

    :-Dan