js讀取Excel檔案資料-IE瀏覽器

來源:互聯網
上載者:User

標籤:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>    

<title> New Document </title>    

<script language="JavaScript">  

<!--

 var excelFileName = "D:\\UserData.xls";  var oWB;

function showExcel()

{

 //objID為表格ID  

//需要在瀏覽器安全層級設定中啟用ActiveX

 // Start Excel and get Application object.     

var oXL=null;     

try{         

oXL = new ActiveXObject("Excel.Application");     

}catch(e)

{       

 

   alert(e.message);          return ;     

}     

if (oXL == null){        

           alert("建立Excel檔案失敗,可能是您的電腦上沒有正確安裝Microsoft Office Excel軟體或瀏覽器的安全層級設定過高!");         

          return;     

}    

try {    

// Get a new workbook.    

  oWB = oXL.Workbooks.Open(excelFileName);    

  for (i = 1; i <= oWB.Sheets.Count; i++) {   

   if (oWB.Sheets(i).name.lastIndexOf("使用者資訊") != -1){    

    showSheet(i);    

  }    

}

 }  catch (e){     

     alert(e.message);

 }  oWB.Close();  

 //不close活頁簿的話,後果還是挺嚴重的。  

oWB = null;  

oXL = null;  

}

function showSheet(sheetNO){  

var oSheet = oWB.Sheets(sheetNO);

 document.write("<table border=‘1px‘>");

 for (i = 1; i <= oSheet.UsedRange.Rows.Count; i++)

{     

document.write("<tr>");   

  for (j = 1; j <= oSheet.UsedRange.Columns.Count; j++){

        value = oSheet.Cells(i, j).value;     

if (value == "undefined"){    

   value = " ";      }   

   document.write(i == 1 ? "<th nowrap=true><b>" : "<td>");     

document.write(value);     

document.write(i == 1 ? "</b></th>" : "</td>");   

  }    

document.write("</tr>");  }  

document.write("</table>");  

oSheet = null;

 }    

</script>

</head>

<body onload="showExcel();">

</body> </html>

js讀取Excel檔案資料-IE瀏覽器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.