導航:首頁 > 版本升級 > http上傳xls文件

http上傳xls文件

發布時間:2024-04-25 22:17:39

⑴ 因需要,用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>

閱讀全文

與http上傳xls文件相關的資料

熱點內容
韓國保險銷售之我的丈夫出去了 瀏覽:396
資料庫表間關系一對多 瀏覽:906
真不卡電影網站 瀏覽:789
土豆網在線網站 瀏覽:695
關鍵路徑演算法java 瀏覽:690
iphone5s撥號界面美化 瀏覽:882
usb的通信程序 瀏覽:109
移動歌曲為什麼找不到指定的文件 瀏覽:129
刪除文件哪裡恢復 瀏覽:946
js打開手機相冊 瀏覽:943
愛奇藝詭異電影 瀏覽:214
日本電影瑪麗的生活的女主角是誰 瀏覽:255
小電影APP直播 瀏覽:791
血在口中西班牙電影 瀏覽:18
r語言怎麼寫入數據 瀏覽:682
乳房電影 瀏覽:266
好看的韓國激情片w 瀏覽:500
瀏覽網站時為什麼不能用wifi 瀏覽:597
台灣金燕電影 瀏覽:651
晚上好看的電影網站 瀏覽:824

友情鏈接