js 对多sheet Excel赋值操作

function ExpExcel(){
      
      var tempStr = "";
      var filePath =""
      var excelname=ReportFileStatus("D:\\张三.xlsx");   // 对Excel多Sheet的操作 
      if(excelname=="Ture")
       {        
           filePath="D:\\张三.xlsx";
       }
      else
       { 
             filePath= "D:\Temp.xlsx";  // 如果不存在当前人的excel就用模板

       }
      var oXL = new ActiveXObject("Excel.application"); 
      
      var oWB = oXL.Workbooks.open(filePath);   
      oXL.Visible = true;
      var sstep=Getvalue("step");
      switch(sstep)
      {
      
       case "1":
            oWB.worksheets(1).select();  // 操作不同的sheet
          break;
          .
          .
          .
          .
          .
          .
    
        }    
      var oSheet = oWB.ActiveSheet;
  
      try{ 
         oSheet.Cells(3,3).value ="";            //cell赋值
         oSheet.Cells(3,6).value = ""; 
           
      }catch(e)
      {        
           oWB.Close();
           oXL.Quit();
           oXl=null; 
      } 
      
        oSheet.SaveAs("D:\\abc.xlsx");   //另存
        oWB.Visible=false;
        oWB.Close();
        oXL.Quit();
        oXl=null;
      
        var idtmr = "";
        idtmr = window.setinterval( "cleanup(); ",1);    //销毁对象
      
}

function Cleanup() { 
window.clearInterval(idTmr); 
CollectGarbage(); 
} 

 

posted @ 2016-12-29 14:12  不必太用力  阅读(1989)  评论(0编辑  收藏  举报