javascript中直接引用Microsoft的COM產生Word

來源:互聯網
上載者:User

 直接引用Microsoft的COM是可以產生Word的,下面為大家介紹下實現的javascript代碼

代碼如下:<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="請假申請單" 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="請假人"; myTable0.cell(1,2).Range.Text="張三"; myTable0.cell(1,3).Range.Text="請假時間"; myTable0.cell(1,4).Range.Text="2006-2-10";  myTable0.cell(2,1).Range.Text="工號"; myTable0.cell(2,2).Range.Text="32412"; myTable0.cell(2,3).Range.Text="填表時間"; myTable0.cell(2,4).Range.Text="2006-2-9";  myTable0.cell(3,1).Range.Text="請假原因"; myTable0.cell(3,2).Range.Text="感冒"; myTable0.cell(3,3).Range.Text="處理方式"; myTable0.cell(3,4).Range.Text="病假";  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="申請人簽名" //空格勿刪 myTable2.cell(1,2).Range.Text="申請人的簽名";  try{ myDocApp.ActiveDocument.SaveAs("e:JaveToWord.doc"); }catch(exception){ alert("瀏覽器安全設定過高,儲存檔案到本地失敗"); myDocApp.Documents.close(); myDocApp.Application.quit(); myDocApp=null; window.close(); } } </SCRIPT> </HEAD> <BODY> <p><a href="javascript:word_onclick()">產生WORD</a></p> </BODY> </HTML>  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.