怎么导入excel文件?并让它以表格形式显示在界面上
在网上看的一个,为什么点击“显示工作簿内容”没效果呢!有大神知道怎么做吗?除了我复制的这个
急,在线等!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript" type="text/javascript">
function importXLS(fileName)
{
objCon = new ActiveXObject("ADODB.Connection");
objCon.Provider = "Microsoft.Jet.OLEDB.4.0";
objCon.ConnectionString = "Data Source=" + fileName + ";Extended Properties=Excel 8.0;";
objCon.CursorLocation = 1;
objCon.Open;
var strQuery;
var strSheetName = "Sheet1$";
var rsTemp = new ActiveXObject("ADODB.Recordset");
rsTemp = objCon.OpenSchema(20);
while(!rsTemp.EOF)
{
if (rsTemp("TABLE_TYPE")=="TABLE")
{
//alert(rsTemp("TABLE_NAME"));
rsExcel = new ActiveXObject("ADODB.Recordset");
strQuery = "SELECT * FROM [" + rsTemp("TABLE_NAME") + "]";
rsExcel.ActiveConnection = objCon;
rsExcel.Open(strQuery);
mm=rsTemp("TABLE_NAME")+"表内容<br><table border='1' cellspacing='0' cellpadding='0'>"
for(i = 0;i<rsExcel.Fields.Count;++i)
{
mm=mm+"<td>"+rsExcel.Fields(i).name+"</td>";
}
while(!rsExcel.EOF)
{
mm=mm+"<tr>"
for(i = 0;i<rsExcel.Fields.Count;++i)
{
mm=mm+"<td>"+rsExcel.Fields(i).value+"</td>";
}
mm=mm+"</tr>"
rsExcel.MoveNext;
}
}
document.write(mm+"</table><br>")
mm=""
rsExcel = null
rsTemp.MoveNext;
}
objCon.Close;
objCon =null;
rsExcel = null;
}
</script>
</head>
<body>
<input type="file" id="f" />
<input type="button" id="b" value="显示工作簿内容" onClick="if(f.value=='')alert('请选择xls文件');else importXLS(f.value)" />
</body>
</html>