复制代码 代码如下: Build Document by Script <BR>function word_onclick() <BR>{ <BR>var myDocApp=null; <BR>myDocApp =new ActiveXObject("word.Application"); <BR>myDocApp.Application.Visible = true; <BR>var myDoc = myDocApp.Documents.Add(); <br><br>myDocApp.Selection.ParagraphFormat.Alignment=1 <BR>myDocApp.Selection.Range.Bold=true; <BR>myDocApp.Selection.Font.Size=22; <BR>myDocApp.Selection.Text="请假申请单" <BR>myDocApp.Selection.insertAfter("\n"); <BR>myDocApp.Selection.MoveRight(2,10); <BR>myDocApp.Selection.TypeParagraph(); <BR>myDocApp.Selection.Font.Bold=false; <BR>myDocApp.Selection.Font.Size=12; <br><br>var myTable0=myDoc.Tables.Add(myDocApp.Selection.Range,3,4); <BR>myTable0.cell(1,1).Range.Text="请假人"; <BR>myTable0.cell(1,2).Range.Text="张三"; <BR>myTable0.cell(1,3).Range.Text="请假时间"; <BR>myTable0.cell(1,4).Range.Text="2006-2-10"; <br><br>myTable0.cell(2,1).Range.Text="工号"; <BR>myTable0.cell(2,2).Range.Text="32412"; <BR>myTable0.cell(2,3).Range.Text="填表时间"; <BR>myTable0.cell(2,4).Range.Text="2006-2-9"; <br><br>myTable0.cell(3,1).Range.Text="请假原因"; <BR>myTable0.cell(3,2).Range.Text="感冒"; <BR>myTable0.cell(3,3).Range.Text="处理方式"; <BR>myTable0.cell(3,4).Range.Text="病假"; <br><br>var range=myDocApp.ActiveDocument.Content; <BR>range.Collapse(0); <BR>range.insertAfter("\n"); <BR>range=myDocApp.ActiveDocument.Content; <BR>range.Collapse(0); <br><br>var myTable2=myDoc.Tables.Add(range,1,2); <BR>myTable2.Columns(1).SetWidth(320,2); <BR>myTable2.cell(1,1).Range.Text="申请人签名" //空格勿删 <BR>myTable2.cell(1,2).Range.Text="申请人的签名"; <br><br>try{ <BR>myDocApp.ActiveDocument.SaveAs("e:\\JaveToWord.doc"); <BR>}catch(exception){ <BR>alert("浏览器安全设置过高,保存文件到本地失败"); <BR>myDocApp.Documents.close(); <BR>myDocApp.Application.quit(); <BR>myDocApp=null; <BR>window.close(); <BR>} <BR>} <BR> 生成WORD