Javascript - Is there a way to export HTML along with formatting to a word document using ActiveX?

2k Views Asked by At

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?

1

There are 1 best solutions below

0
On

You can achieve it without using ActiveX. Check this.