Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2006

Tip: Looking for answers? Try searching our database.

Insert HTML "blob" into existing document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bpsmicro - 18 Sep 2006 14:54 GMT
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.
Cindy M. - 19 Sep 2006 12:26 GMT
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
[quoted text clipped - 6 lines]
> 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 :-)
bpsmicro - 19 Sep 2006 13:58 GMT
<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.

> Hi =?Utf-8?B?YnBzbWljcm8=?=,
>
[quoted text clipped - 17 lines]
> the InsertXML command. Word does do WordProcessingML to binary in the object
> model.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.