标题:怎么导入excel文件?并让它以表格形式显示在界面上
只看楼主
CassieC
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2016-7-7
 问题点数:0 回复次数:0 
怎么导入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>
搜索更多相关主题的帖子: javascript function content PUBLIC excel 
2016-07-12 14:30



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-466858-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.120811 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved