Insert HTML "blob" into existing document

B

bpsmicro

From a user perspective, I can copy a blob of HTML from somewhere and paste
it into a Word document (Word 2003 in this case), and all the formatting is
preserved.
I need to be able to do this programmatically. I have a blob of "raw" HTML
code that I want to insert at a given point. I tried Range.InsertBefore and
all I got was the HTML codes.

I'm guessing (though I haven't yet tried) that I could stuff my blob onto
the clipboard and use the Range.Paste method, but that approach just seems so
lame to me. I'm sure (hopeful?) there's just some simple thing I'm not seeing
in my searches.

I'm actually working in C++ and C# (not using VSTO though), but since it's
all the same object model, I can "translate" VBA examples easily enough. Any
pointers greatly appreciated.

Brad.
 
C

Cindy M.

Hi =?Utf-8?B?YnBzbWljcm8=?=,
From a user perspective, I can copy a blob of HTML from somewhere and paste
it into a Word document (Word 2003 in this case), and all the formatting is
preserved.
I need to be able to do this programmatically. I have a blob of "raw" HTML
code that I want to insert at a given point. I tried Range.InsertBefore and
all I got was the HTML codes.

I'm guessing (though I haven't yet tried) that I could stuff my blob onto
the clipboard and use the Range.Paste method, but that approach just seems so
lame to me.
Yes, that's what you'd need to do. Or write it to a file then use InsertFile.

Problem is, Word requires a converter to turn HTML into Word document binary.
And converters are only available through Paste or when opening a file.

What you could do is transform the HTML into valid WordProcessingML, then use
the InsertXML command. Word does do WordProcessingML to binary in the object
model.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
B

bpsmicro

<groan>

Well I did some Googling and it looks like I'd have to spend a bunch more
time than I have designing and writing an HTML->WordProcessingML from scratch.

The InsertFile approach looks promising though. And I found that if I
specify the Link parameter as true to insert it as an INCLUDETEXT field then
from then on I only need to call Update on the field that's created and it'll
update any "behind-the-scenes" changes to the file I maintain. I think I'll
proceed with that approach.

Many thanks;
Brad.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top