views:

154

answers:

2

How can i convert the text with html tag to formated word document. Actually what i need to do is, I want to give text with the html tag as input in a text box, and when i click a button, i want the the text to be open in a word document where the html tags are removed and the text appears in its corresponding format.

A: 

Make a regular html file and save it with .doc extension. It will be well displayed in ms word.

Rodrigo
A: 

I wonder if you were stuck by the loss of formatting when you saved an HTML file as a Word doc. I was. I figured out that multiple classes are not carried over, nor anything based on multiple classes.

Consider this:

<p class="class1">This <span class="class1 class2">is my</span> text.</p>

.class1 { color:green; }
.class2 { color:orange; }

.class1.class2 { color:red; }

.class1.class2,
.class1 { color:blue; }

Results in:

  1. p is green because its first declaration holds
  2. p is not blue because that declaration is part of an 'invalid' multi-class declaration (!)
  3. span is orange because its first declaration holds
  4. As with point 2. span is not red, nor blue, because of the 'invalid' multi-class declarations

--

As a result of the above findings, I ended up wrapping my elements in another element, always with a single markup class name, and formating things successfully on that basis.

Note that it's fine to manipulate elements with Javascript, adding/removing extra class names as required, Word is only interested in the actual markup in the HTML file it is trying to parse.

What I didn't figure out is how to get CSS background images to show up when HTML files are opened by Word. I usually use the shortcut: background:transparent url(../img/icon-audio-16.gif) left top no-repeat; which didn't work (yes, checked my paths), but then neither did a blow-by-blow breakdown:

background-color:transparent;
background-image:url(../img/icon-audio-16.gif);
background-position:left top;
background-repeat:no-repeat;

Anyway...

Danjah