COM that directly references Microsoft in JavaScript to generate word

Source: Internet
Author: User

  Direct reference to Microsoft's COM is to generate word, the following is a description of the implementation of the JavaScript code

The 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 request 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 (1,1). range.text= "Leave person";  Mytable0.cell (1,2). range.text= "John";  Mytable0.cell (1,3). Range.text= "Leave Time";  Mytable0.cell (1,4). range.text= "2006-2-10";    Mytable0.cell (2,1). range.text= "Work number";  Mytable0.cell (2,2). range.text= "32412";  Mytable0.cell (2,3). range.text= "Filling time";  Mytable0.cell (2,4). range.text= "2006-2-9";    Mytable0.cell (3,1). range.text= "Reason for absence";  Mytable0.cell (3,2). range.text= "Cold";  Mytable0.cell (3,3). range.text= "processing mode";  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 (1,1). range.text= "Applicant Signature"//Space not deleted   Mytable2.cell (1,2). range.text= "Applicant's signature";    try{  myDocApp.ActiveDocument.SaveAs ("E:javetoword.doc"); }catch ( Exception) {  alert ("Browser security settings are too high, save files to local failure");  MyDocApp.Documents.close ();  Mydocapp.appLication.quit ();  mydocapp=null;  window.close (); } }  </SCRIPT>  </head >  <BODY>  <p><a href= "Javascript:word_onclick ()" > Generation word</a></p>  </BODY>  </HTML>   
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.