Pasting edited HTML into Word via interop

S

snixtor

I've got a custom HTML editor that I'm using Word interop to perform
spell checking. I'm getting the HTML into Word via clipboard copy /
paste using the method "PasteSpecial". Ordinarily this has worked
fine, but recently I've had reason to edit the content of the HTML
before pasting it into Word, that is, removing image tags before
sending it for a spell-check, because Word (2007) modifies the image
tags and makes them invalid for my application. The trouble is, as
soon as I edit out the image tags, PasteSpecial no longer functions
properly, throwing the error "Command Failed". Similarly, if I just
cobble together a bit of HTML manually (with much less metadata than
normally generated) and send it to Word via PasteSpecial I get the
same error.

What could be causing this? When I'm stripping the img tags the HTML
I'm sending to Word looks pretty standard, the only difference is the
img tag is pulled out, but somehow that upsets Word.
 
S

Snixtor

Ah-ha, I found the answer, Word insists on having a well-formatted
header looking like this:

Version:1.0
StartHTML:000000151
EndHTML:000000376
StartFragment:000000265
EndFragment:000000340
StartSelection:000000265
EndSelection:000000340

Modify the content and those indexes are out and Word throws a
wobbly. Correct them and all is well.
 

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