Jsp generates Word document format data code

Source: Internet
Author: User

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 ;","");

}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.