用JAVASCRIPT在客户端启动WORD,并排版WORD的格式,形成一个报表

类别:编程语言 点击:0 评论:0 推荐:
   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)

本文地址:http://com.8s8s.com/it/it27792.htm