Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically clean Word-generated HTML while preserving styles?

In my current company, we have this decade old...let's call it a "Hello World" application.

While wanting to create a newer version of it, we also want to preserve older entries. These older entries contain hideous Word-generated HTML which was never filtered before.

If and when we move to a newer system, I'd prefer to have that HTML cleaned and filtered in order to have the site comply with HTML standards as much as possible.
However, just cleaning that code like Jeff Atwood described in his blog or in any other way I know of would also ruin the style and formatting.

Now, that just might cause our users to revolt and then all hell will break loose - not a very good idea.

So the question is: Can Word's HTML be cleaned while preserving basic formatting? (e.g: coloring, italicized, bold text and so on)

Preferably using publicly available code or library, such as HTML Tidy, examples in C# would be much appreciated.

like image 281
GeReV Avatar asked May 10 '10 21:05

GeReV


1 Answers

There are a couple of options available, but you can certainly use Jeff Atwood's as a good starting point to code your own. If so, you'll likely get fine-tuned control over the result - note though that the results will be never been 100% accurate as all that extra ms-code is actually there to ensure as much fidelity with the original document as possible (at least in IE for round-tripping purposes). But most code out there does preserve most formatting.

Here are some code libraries that could be helpful:

If you're just wanting batch-processing (and don't care about owning a code base), the Office 2000 HTML Filter 2.0 is probably your best best - read more about it on TechRepublic.

like image 168
Todd Main Avatar answered Nov 15 '22 20:11

Todd Main