BJury
BJury

Reputation: 2604

Pasting HTML into Word While Keeping Non-visible Data

I think everyone in the world who has anything do to with IT hates the Word HTML editing which Outlook uses. Especially if you're trying to maintain formatting in the email.

However I have an issue that is unlike most of the problems which come with having to use Outlook as an HTML email editor.

I have an application which outputs HTML, which in turn gets emailed to various people. The HTML formats fine and everything looks dandy. What I need to do is embed a guid into a HTML table so that they are not visible, but survive the paste into Word. Ideally this data would be non visible so it can't be easily discovered in email editor. (Its just a guid, so having users able to find it would just make the mail ugly.)

Word seems to transform the HTML so that there is no CSS, nor any attributes appear to be maintained. (Eg, id="")

You can do things like set the font-size to 0, which on a browser means it's not rendered, however Word does render it. Also if you copy paste it into Excel its easily seen, even if the foreground colour is set to the background colour.

So does anyone know of a way to get data into HTML in word, with your own metadata intact? (Oh and pasting the guid visibly in the signature or whatever isn't an option, as the HTML table is generally put in larger emails, along with other outputs from the same app.)

Edit:

The best I've found so far is:

<table><tr>
<td>Some text<a href="http://foobar.com/#--guid--" style="font-size:0px; width=0px">&nbsp;</a></td>
</tr></table>

You can't see the link at all unless you zoom in a lot, however when pasted to Excel it changes the whole cell into a link with the guid, so far from ideal.

Edit 2:

So you can stop Excel from turning the cell into a hyperlink by adding a second link. This might be enough for my purpose, however the elements are still visible if you zoom and who knows what other clients will do with it. So I'm still looking for a 'perfect' solution...

<table><tr>
<td>Some text
<a href="http://foobar.com/#--guid--" style="color:white;font-family:times new roman;font-size:0px; width=0px">&nbsp;</a>
<a href="http://foobar.com/" style="color:white;font-family:times new roman;font-size:0px; width=0px">&nbsp;</a></td>
</tr></table>

The font family is important, as Word seems to be able to render the font at 0px, while others like Verdana it doesn't seem to be able to so you get a 'dot'.

Upvotes: 2

Views: 1056

Answers (1)

noseratio
noseratio

Reputation: 61666

Use mso-ignore CSS attribute. The following has been tested with Word 2010.

The HTML source (open in IE, copy with Ctrl+A, Ctrl+C and paste into Word)

<body>
Before <span style="display: none; mso-ignore: display;">0299E8BF-5408-4E1C-959F-2FA6495100D3</span> After
</body>

Save the Word document as an HTML file. The GUID will stay hidden. Saving from Word as HTML, the output is:

<p class=MsoNormal>Before <span style='display:none;mso-hide:all'><span
style='mso-ignore:display'>0299E8BF-5408-4E1C-959F-2FA6495100D3</span></span>
After</p>

Upvotes: 1

Related Questions