源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-07-02 07:05 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:javascript中直接引用Microsoft的COM生成Word
[u]复制代码[/u] 代码如下:
<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>
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部