设为首页
加入收藏
帮助中心
首页 | 红盾通告 | 信息中心 | ASP技术 | 数据库 | 网页设计 | 网管专栏 | OICQ攻略 | 墨客频道 | 网站运营 |
当前位置:首页 >> ASP技术 >> ASP应用 >> 正文
最新信息
·asp无限级分类加js收缩伸展…
·ASP读取EXCEL数据
·ASP编程操作Excel
·ASP编写了一个EXCEL上传程…
·ASP如何读取EXCEL工作表名…
·ASPJpeg和ASPUpload组件的…
·用ASP和SQL语句动态的创建…
·asp生成excel报表
·四大 FCKeditor 实战应用技…
·FCKeditor 2.0 的设置.修改…
资料搜索
热点信息
·asp生成excel报表
·Javascript+ASP制作树形菜…
·AspUpload组件的UploadedF…
·ASPJpeg和ASPUpload组件的…
·FckEditor中文配置手册详细…
·ASPUpload组件介绍
·金光ASP柱形图程序
·asp生成不重复的随机数字
·ASP读取EXCEL数据
·0-29内取15个不同的随机数…
推荐信息
·用ASP生成二维饼图
·一个取图片尺寸的类,支持…
·随即文件名
·ASP 随机图片
·本地图片,音乐等ASP防盗代…
·ASPJpeg和ASPUpload组件的…
·如何实现网上考试?
·用ASP打开远端MDB文件的方…
·ASP编写完整的一个IP所在地…
·用ASP实现远程批量文件改名


Google
 
ASP编写了一个EXCEL上传程序,并且把上传的EXCEL数据导入到已经建好的ACCESS数据表中
〖浏览:人次〗

upload.asp

<html>
<head>
<title>上传文件</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="css/css.css" rel="stylesheet" type="text/css" />
</head>
<script>
if (top.location==self.location)
{
    top.location="index.asp"
}
</script>
<body leftmargin="0" topmargin="0">
<table width="100%" border=0 cellspacing=0 cellpadding=0>
<form name="form" method="post" action="readxls.asp" enctype="multipart/form-data">
    <tr>
          <td>
   <input name="file1" type=file class=input-text size="30">
  <input type=submit name="submit" value="导入数据" style="width:70px; height:19px;" >
         </td>
   </tr>
</form>
</table>
</body>
</html>

--------------------------------------
-------上传并且写入库-----------
readxls.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="upload_5xsoft.inc"-->
<!--#include file="common/db_conn.asp"--> 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>EXECL数据导入</title>
<style type="text/css">
<!--
body,td,th {
 font-size: 12px;
 color: #666666;
}
-->
</style>
</head>
<body>
<%
session.CodePage=936
Server.ScriptTimeOut=600000
set upload=new upload_5xsoft
set file=upload.file("file1")
if file.fileSize>120000 then
%>
<script>
alert("您选择的文件过大!");
window.close();
</script>
<% end if
if file.fileSize>0 then
    filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)
    filename=filename+"."
    filenameend=file.filename
    filenameend=split(filenameend,".")
    if filenameend(1)="xls" then
        filename=filename&filenameend(1)
        file.saveAs Server.mappath("uploadfile/"&filename)
    else
        response.write "数据格式不对!"
        response.write "<a href=upload.asp>返回</a>"
  response.end()
    end if
    set file=nothing
else
        response.write "文件不能为空!"
        response.write "<a href=upload.asp>返回</a>"
  response.end()
End if
set upload=nothing

'上传XLS文件结束,下面从上传的XLS文件中读取数据写入到SQL数据库
   strAddr=server.MapPath("uploadfile/"&filename)
   set excelconn=server.createobject("adodb.connection")
   excelconn.open "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = "+strAddr+";Extended Properties='Excel 8.0;HDR=NO;IMEX=1'"
 set rs=server.CreateObject("adodb.recordset")
 set rs1=server.CreateObject("adodb.recordset")
 sql="select * from [Sheet1$]"
 rs.open sql,excelconn,1,1
 if not(rs.bof and rs.eof) then
  rs.movenext
  do while not rs.eof
    sql1="select * from [Fees_Asse_T] where id is null"
    rs1.open sql1,conn,1,3
    rs1.addnew
       rs1("Cate_Code")=rs(0)
       rs1("Asse_Code")=rs(1)
       rs1("Asse_Name")=rs(2)
       rs1("Categories")=rs(3)
   rs1.update
   rs1.close
   rs.movenext
  loop
 end if
 rs.close() 

 set rs=nothing
 set rs1=nothing

 excelconn.Close()  
 set excelconn=nothing

 conn.close()
 set conn=nothing
%>
 <script>
   alert("数据导入成功!");
   window.parent.document.location.reload();
   history.back();
 </script>
</body>
</html>


录入时间:2009-11-24 14:03:46 [打印本页] [关闭窗口] [返回顶部]
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。

Copyright © 2006-2014 0733168.Com Inc All Rights Reserved
关于我们 | 广告合作 | 联系我们 | 法律声明 | 友情链接 | 意见反馈
本站所收录信息、社区话题、及本站所做之广告均属其个人行为,与本站立场无关
湘ICP备06008436号