javascript在用戶端啟動WORD,並排版WORD的格式,形成一個報表

來源:互聯網
上載者:User
 var title = document.forms[0].title.value    //取報表標題
     if (title.length<1 )
     {
       alert("報表資料不存在,請進行統計")
       return;
     }
    
     var ksrq = document.forms[0].bbksrq.value
     var jsrq = document.forms[0].bbjsrq.value
     var row_count = document.forms[0].row_count.value
     var col_count = document.forms[0].col_count.value
     var zd = document.forms[0].zd.value
     var context = document.forms[0].context.value
     var temp
    
     var i=0,n =0
     var vzd = new Array();
     var vcontext = new Array();
     var vcontext1 = new Array();
     vzd = zd.split("\\");
   
 var WordApp=new ActiveXObject("Word.Application");    //得到WORD對象
   
 var wdCharacter=1
 var wdOrientLandscape = 1
 WordApp.Application.Visible=true;
 var myDoc=WordApp.Documents.Add();
 
     WordApp.ActiveDocument.PageSetup.Orientation = wdOrientLandscape
 
 
     WordApp. Selection.ParagraphFormat.Alignment=0  //置中對齊
 WordApp. Selection.Font.Bold=true
     WordApp. Selection.Font.Size=20
    
     WordApp. Selection.TypeText(title+"("+ksrq+"至"+jsrq+")");
     WordApp. Selection.MoveRight(wdCharacter);//游標右移字元
     WordApp.Selection.TypeParagraph()//插入段落
     WordApp.Selection.TypeParagraph()//插入段落
    
    
    
    var myTable=myDoc.Tables.Add (WordApp.Selection.Range, row_count,col_count)  //五行4列的表格
     
     
     
     var TableRange;  //以下為給表格中的儲存格賦值
     for (i= 0;i<vzd.length;i++)
     {
     with (myTable.Cell(1,i+1).Range)
     {font.Size = 12;
 InsertAfter(vzd[i]);
 }
 }
 
 for (i =0;i<row_count-1;i++)
 {
 vcontext = context.split("<縱標>")
 for (n =0;n<col_count ;n++)
 {
 temp = vcontext[i]
     vcontext1 = temp.split("<標記>")
    
     with (myTable.Cell(i+2,n+1).Range)
     {font.Size = 12;  
 InsertAfter(vcontext1[n]);
 }
}
}
     row_count = 0;
     col_count = 0
 myDoc.Protect(1)
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.