Copy codeThe Code is as follows:
<Html>
<Head>
<Meta http-equiv = Content-Type content = "text/html; charset = UTF-8">
<Title> Build Document by Script </TITLE>
<Script language = "text/javascript">
Function word_onclick ()
{
Var myDocApp = null;
MyDocApp = new ActiveXObject ("word. Application ");
MyDocApp. Application. Visible = true;
Var myDoc = myDocApp. Documents. Add ();
MyDocApp. Selection. ParagraphFormat. Alignment = 1
MyDocApp. Selection. Range. Bold = true;
MyDocApp. Selection. Font. Size = 22;
MyDocApp. Selection. Text = "Leave Application Form"
MyDocApp. Selection. insertAfter ("\ n ");
MyDocApp. Selection. MoveRight (2, 10 );
MyDocApp. Selection. TypeParagraph ();
MyDocApp. Selection. Font. Bold = false;
MyDocApp. Selection. Font. Size = 12;
Var myTable0 = myDoc. Tables. Add (myDocApp. Selection. Range, 3, 4 );
MyTable0.cell (). Range. Text = "requester ";
MyTable0.cell (1, 2). Range. Text = "Zhang San ";
MyTable0.cell (1, 3). Range. Text = "Time for leave ";
MyTable0.cell (1, 4). Range. Text = "2006-2-10 ";
MyTable0.cell (2, 1). Range. Text = "employee ID ";
MyTable0.cell (32412). Range. Text = ";
MyTable0.cell (2, 3). Range. Text = "" ";
MyTable0.cell (2, 4). Range. Text = "2006-2-9 ";
MyTable0.cell (3, 1). Range. Text = "reason for leave ";
MyTable0.cell (3, 2). Range. Text = "catch a cold ";
MyTable0.cell (3, 3). Range. Text = "Processing Method ";
MyTable0.cell (3, 4). Range. Text = "Sick leave ";
Var range = myDocApp. ActiveDocument. Content;
Range. Collapse (0 );
Range. insertAfter ("\ n ");
Range = myDocApp. ActiveDocument. Content;
Range. Collapse (0 );
Var myTable2 = myDoc. Tables. Add (range, 1, 2 );
MyTable2.Columns (1). SetWidth (320,2 );
MyTable2.cell (). Range. Text = "requester signature" // do not delete Spaces
MyTable2.cell (1, 2). Range. Text = "requester's signature ";
Try {
MyDocApp. ActiveDocument. SaveAs ("e: \ JaveToWord.doc ");
} Catch (exception ){
Alert ("failed to save the file to the local device because the browser security settings are too high ");
MyDocApp. Documents. close ();
MyDocApp. Application. quit ();
MyDocApp = null;
Window. close ();
}
}
</SCRIPT>
</HEAD>
<BODY>
<P> <a href = "javascript: word_onclick ()"> Generate WORD </a> </p>
</BODY>
</HTML>