Link to home
Start Free TrialLog in
Avatar of HarleyInDTX
HarleyInDTX

asked on

Creating tables with alternating text in Word using Javascript

I am trying to create a MS Word doc with Javascript. I have had some success with being able to either create the table or the text and populate the table cells with values. When I try to alternate a table then text then another table, the text ends up in the first cell of the first table. This is run from an IE browser.
What am I missing?

function fnCreateWord() {
	var objWord = new ActiveXObject("Word.Application");
	objWord.Caption = "Test";
 
	objDoc = objWord.Documents.Add()
	objWord.Application.Visible = true;
	objSelection = objWord.Selection;
	
	var tbl = objDoc.Tables.Add(objWord.Selection.Range,4,3);
 
// The following is placed properly into the second cell and second column. 	
	var cCell = tbl.cell(2,2).range;
	tbl.cell(2,2).Column.Width = 100;
	cCell.Font.Bold = true;
	cCell.Font.Size = "18";
	cCell.text =  "ZZZZZZZZZZZZ";
 
// The following ends up in first row and the first column of tbl. It needs to be after the table. 
	objSelection.Font.Name = "Arial";
	objSelection.Font.Size = "18";
	objSelection.TypeText("AAAAAAAAAAAAAA");
	objSelection.TypeParagraph();
 
	objSelection.Font.Size = "14";
	objSelection.TypeText("" + Date() );
	objSelection.TypeParagraph();
	objSelection.TypeParagraph();
// There needs to be another table inserted here with more text following. 
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Pravin Asar
Pravin Asar
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial