How to insert or embed a html file in to a Word doc ?

S

Summer

Hello,

I am trying to embed a html file (a report from sql) in to a word document
in a particular location.
I am trying to get this done using the Office Interop and Python.

1) How can I embed a html file in to a word document ?
2) How can I embed it on to a location by replacing a token in the Word doc.
Eg . The word file would have a token <html_report>. The HTML file has to be
embedded in the place where This token is .

Thanks !
 
P

Paul Shapiro

I've written Word VBA code (not VSTO) to insert html-formatted text into a
Word document, and never found a completely good way to go about it. The
most reliable approaches I found were:
a) Save the html text to a file with the .html exension and then use Word's
InsertFile method. This is simple and straightforward.
b) Copy the html to the clipboard, in the very particular html clipboard
format, and then Paste into the document. This is what I ended up using
because saving the html to a file seemed so stupid, and slow (although I
didn't compare performance).

I spent a long time hunting for the .InsertHTML method, because I couldn't
believe it didn't exist by now. But as far as I can tell it does not exist
so the above two options were the best I could do.

Email me (after making the obvious correction to my email address) if you
want a copy of the code for option b. It's too long to post here.
 
S

Summer

Paul, Thanks for your response to my question on how to embed a html file in
to a word doc using Interop.

But I was able to embed a html file to the word doc using '
document.InlineShapes.AddOLEObject ' . (I did observe that it takes a minute
to open the HTML file, when the icon is clicked . But I thought I would worry
about the response time in the next stage).

Where I am is stuck is, trying to embed the file in a desired location . Eg:
Find a particular token or string in the word doc and embed the file in that
location . I am sure this is to do with the 'Range' object , but still could
not figure it out. So any insight on this would be great !

Thanks !!
 
S

Summer

Paul, I could not figure out that obvious correction to your email that is
needed. It would be great if you can send your code for option B to
me.too.engineerATgmailDOTcom
 
P

Paul Shapiro

You have to find the location where you want to insert the text. This would
be the same for any text replacement. If you don't know the location in
terms of paragraphs, or some other fixed reference, you can use Word's Find.
Or use a bookmark in the document and you can replace the bookmark text. I
don't do enough Word coding to remember the syntax, but I'm sure you can
find samples of these by searching.

I'll email the code to the address you gave.
 
C

Cindy M.

Hi Summer,
But I was able to embed a html file to the word doc using '
document.InlineShapes.AddOLEObject ' . (I did observe that it takes a minute
to open the HTML file, when the icon is clicked . But I thought I would worry
about the response time in the next stage).

You need to be aware, if you want to use this approach, that it *requires* the
presence of an application, installed *and registered* on the machine as a valid
OLE SERVER. It's quite possible that, when you distribute such a solution, that
(by default) not all client machines would have the application that's installed
on your machine - this is *not* part of Word-out-of-the-box (or Office).

Also, you probably won't be able to do much about the "response time". When an
OLE Server is in play, a lot of factors are involved, including any security
mechanisms at the Windows level that may monitor and manage OLE Client/Server.
It's just generally slow...

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 :)
 
I

icsonu

Can I Embed a Word File in a Excel file. becoz i have seen it which have a
formula =Embed(Worddoc.12," ") to that embeded word file.
 

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