1. Copy jsp page data to Word documents
Var table = document. getElementById (printTable );
Row = table. rows. length;
Column = table. rows (1). cells. length;
Var word = new ActiveXObject ("Word. Application ");
Word. Application. Visible = true;
Word. Selection. Text = "<% = reportTitle %> ";
Var mydoc = word. Documents. Add (, 0, 0 );
MyRange = mydoc. Range (0, 1 );
Var sel = document. body. createTextRange ();
Sel. moveToElementText (table );
Sel. select ();
Sel.exe cCommand (Copy );
MyRange. Paste ();
2. Write jsp page data into WORD Documents
Var table = document. getElementById (printTable );
Row = table. rows. length;
Column = table. rows (1). cells. length;
Var wdapp = new ActiveXObject ("Word. Application ");
Wdapp. visible = true;
Wddoc = wdapp. Documents. Add (); // Add a new document
Thearray = new Array ();
// Store the table content on the page in an array
For (I = 0; I <row; I ){
Thearray [I] = new Array ();
For (j = 0; j <column; j ){
Thearray [I] [j] = table. rows (I). cells (j). innerHTML;
}
}
Var range = wddoc. Range (0, 0 );
Range. Text = "<% = reportTitle %> """;
Wdapp. Application. Activedocument. Paragraphs. Add (range );
Wdapp. Application. Activedocument. Paragraphs. Add ();
Rngcurrent = wdapp. Application. Activedocument. Paragraphs (3). Range;
Var objTable = wddoc. Tables. Add (rngcurrent, row, column) // insert a table
For (I = 0; I <row; I ){
For (j = 0; j <column; j ){
ObjTable. Cell (I 1, j 1). Range. Text = thearray [I] [j]. replace ("& nbsp ;","");
}
}