3

I figured out a way to write to word using an ActiveX component but I am not sure if its possible to write HTML to Word,

function generateWord(elementIdValue){

  var value=$("#"+elementIdValue)).html();

  var word= new ActiveXObject('Word.Application');
  word.Visible=true;
  var doc=word.Documents.Add();
  var sel=word.Selection;
  sel.TypeText(value);

}

I don't want to save HTML directly to word (It wouldn't be readable with all html tags), rather want to write the data along with HTML styling in word.

I had successfully written HTML to Outlook along with formatting using HTMLBody property,

var objO = new ActiveXObject('Outlook.Application');     
var objNS = objO.GetNameSpace('MAPI');     
var mItm = objO.CreateItem(0);     
mItm.To = "";
mItm.Subject = "Test";
mItm.HTMLBody = (($(("#"+elementIdValue)).html())

Is there a property in word object similar to Outlook object that can consume HTML?

Vijay Sarin
  • 1,326
  • 1
  • 11
  • 31
Learner
  • 2,303
  • 9
  • 46
  • 81
  • Grabbing the HTML does not mean you'll get the associated styling with it. What is your goal? – Diodeus - James MacFarlane Feb 01 '13 at 20:59
  • My goal is to maintain formatting when writing to word document. I am trying to achieve same effect as copying the html data and pasting to word (this will just paste the data along with formatting). – Learner Feb 01 '13 at 21:01
  • 3
    It will never work. The MS Word HTML rendering engine is absolute crap. You're better of generating a PDF. – Diodeus - James MacFarlane Feb 01 '13 at 21:03
  • It's always worked for me to use a full HTML document as the contents of a Word Doc. To see for yourself, essentially just change the file extension from .html to .doc(x)... Word will render it the very best it can. – wxactly Feb 11 '13 at 04:29

1 Answers1

0

You can achieve it without using ActiveX. Check this.

Debiprasad
  • 5,895
  • 16
  • 67
  • 95