• 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>

  • 相关阅读:
    [HDU 2553] N皇后问题
    [ZOJ 3063] Draw Something Cheat
    [ZOJ 3609] Modular Inverse
    [ZOJ 3610] Yet Another Story of Rock-paper-scissors
    [ZOJ 3607] Lazier Salesgirl
    [ZOJ 3710] Friends
    [ZOJ 3076] Break Standard Weight
    智慧树自动刷课代码
    Attention
    sizeof总结
  • 原文地址:https://www.cnblogs.com/gsbhz/p/1877624.html
Copyright © 2020-2023  润新知