js读取Excel文件数据-IE浏览器
<!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>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。