如何使用Jscript编写EXCEL导出

发布时间:2021-11-18 10:34:04 作者:小新
来源:亿速云 阅读:207

这篇文章主要介绍了如何使用Jscript编写EXCEL导出,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。



function exportexcel()
{
   var iSubjectNum,iElementNum;    
   var sText;    
   var iX=1;
   var iY=2;
   var xlsub;
//   alert(‘export‘);
IniExcel();
xlApp.visible=false;  
   if (fso.FileExists(sExcelPath)==true ) {
       xlsub=xlApp.Application.Workbooks.Open(sExcelPath);  
       //alert(xlsub);
       //xlsub=xlApp.Application.Worksheets(ipage);                
       
    }    
    else{
       xlApp.Workbooks.Add();
       //xlsub=xlApp.Application.Worksheets(1);              
       //ipage=1;
    }        
   var sheetcount=xlApp.Application.Worksheets.Count;    
   var addcount=ipage-sheetcount;    
   if (addcount!=0){
      for(var m=0;m         xlApp.Application.Worksheets.Add();  
   }
   
  //Ñ°ÕÒÊÇ?ñÓÐÏàͬµÄSHEET        
  var bFlag=false;
  var isheetpos=-1;  
  for (var n=1;n<=sheetcount;n++) {          
    if (xlApp.Application.Worksheets(n).Name==("Sheet"+ipage.toString())) {                          
          bFlag=true;          
          isheetpos=n;
      }
     
 }    
 if (bFlag==false )
   {   xlApp.Application.Worksheets.Add();  
      ipage=1;    
   }
   else
   {
      ipage=isheetpos;
   }  
 
   xlsub=xlApp.Application.Worksheets(ipage);                
xlsub.Cells(1,1).Value =oHead.ReportName.toString();    
sText=of_convert_char(1)+"1:"+of_convert_char(iColumnNum)+"1";
xlsub.Range(sText).Merge(true);    
xlsub.Range(sText).HorizontalAlignment=3;
xlsub.Range(sText).Font.Size=20;
xlsub.Range(sText).Font.Bold=true;
iSubjectNum=oHead.oSubject.length;
iY=iY+1;
   for(var i= 0; i<iSubjectNum;i++) {                                
if (oHead.oSubject[i].oElement==null){    
   xlsub.Cells(iY,iX).Value =oHead.oSubject[i].SubjectName.toString();
   var temp=iY+3;
   sText=of_convert_char(iX)+iY.toString()+":"+of_convert_char(iX)+temp.toString();    
   xlsub.Range(sText).Merge(false);
   xlsub.Range(sText).HorizontalAlignment=3;  
   xlsub.Range(sText).Borders.LineStyle=1;                                
   xlsub.Range(sText).Font.Size=10;
   continue;
   }
   else
     iElementNum= oHead.oSubject[i].oElement.length;                    
      xlsub.Cells(iY,iX).Value =oHead.oSubject[i].SubjectName.toString();                            
      sText=of_convert_char(iX)+iY+":"+of_convert_char(iX+iElementNum-1)+iY;
      xlsub.Range(sText).Merge(true);    
      xlsub.Range(sText).HorizontalAlignment=3;  
      xlsub.Range(sText).Borders.LineStyle=1;
      xlsub.Range(sText).Font.Size=10;
      iY=iY+1;
      for(var j=0;j<iElementNum;j++){          
xlsub.Cells(iY,iX).Value =oHead.oSubject[i].oElement[j].ElementName.toString();
   var temp=iY+2;
   sText=of_convert_char(iX)+iY.toString()+":"+of_convert_char(iX)+temp.toString();    
   xlsub.Range(sText).Merge(false);
   xlsub.Range(sText).HorizontalAlignment=3;  
   xlsub.Range(sText).Borders.LineStyle=1;
   xlsub.Range(sText).Font.Size=10;
   iX=iX+1;
 }
      iY=iY-1;      
   }
   iY=iY+3;    
   for (var i=0;i<iRowNum;i++)     {

     iY++;    
     for (var j=0 ;j<iColumnNum;j++)       {

       xlsub.Cells(iY,j+1).Value=oBody[i][j].toString();
       xlsub.Cells(iY,j+1).Borders.LineStyle=1;
       xlsub.Cells(iY,j+1).Font.Size=10;
     
     }

    }    
    if (fso.FileExists(sExcelPath)==true ) {  
         var thiswork=xlApp.Application.ActiveWorkbook;
             thiswork.Saved=true;        
             thiswork.Save();
             thiswork.Close(true);        
    }    
    else
        xlsub.SaveAs(sExcelPath);
    window_onunload();
    alert("Îļþ´æ?ÅÔÚ£º"+sExcelPath);    
}

感谢你能够认真阅读完这篇文章,希望小编分享的“如何使用Jscript编写EXCEL导出”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!

推荐阅读:
  1. JScript实现地址选择功能
  2. JScript有哪些错误代码

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

excel jscript

上一篇:JavaScript如何解决IE6与IE8兼容性问题

下一篇:在 JBuilder 中如何使用 Log4j

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》