zoukankan      html  css  js  c++  java
  • js读取本地excel文档数据

    以下代码在需要设置IE安全级别低才能正常运行,贴出来主要是可以学习这方面的技术

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
      <title>js读取本地excel文档数据 </title>
      <script>
    	function readThis(){
    		var tempStr = "";
    		var filePath= document.all.upfile.value;
    		var oXL = new ActiveXObject("Excel.application"); 
    		var oWB = oXL.Workbooks.open(filePath);
    		oWB.worksheets(1).select(); 
    		var oSheet = oWB.ActiveSheet;
    		try{
    			for(var i=1;i<46;i++){
    				if(oSheet.Cells(i,1).value =="null" || oSheet.Cells(i,2).value =="null" )
    					break;
    				var a = oSheet.Cells(i,1).value.toString()=="undefined"?"":oSheet.Cells(i,1).value;
    				tempStr+=(
    				"  "+oSheet.Cells(i,1).value+
    				"  "+oSheet.Cells(i,2).value+
    				"  "+oSheet.Cells(i,3).value+
    				"  "+oSheet.Cells(i,4).value+
    				"  "+oSheet.Cells(i,5).value+
    				"  "+oSheet.Cells(i,6).value+"\n");
    			}
    		}
    		catch(e){
    			document.all.txtArea.value = tempStr;
    		} 
    		document.all.txtArea.value = tempStr;
    		oXL.Quit();
    		CollectGarbage();
    	}
    	</script>
     </head>
    
     <body>
    	<input type="file" id="upfile" /><input type="button" onclick="readThis();" value="读取">
    	<br />
    	<textarea id="txtArea" cols=100 rows=30></textarea>
     </body>
    </html>

  • 相关阅读:
    特殊json处理
    css3
    居中定位
    微信支付
    vue 封装cookie,请求,登录拦截,接口拦截
    vue中axios的封装(简易版拦截,get,post
    JS的Event Loop
    JS模块化
    JS的排序算法
    时间复杂度 空间复杂度
  • 原文地址:https://www.cnblogs.com/gsbhz/p/1877624.html
Copyright © 2011-2022 走看看