upload.asp
乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > 因需要,用<em>ASP</em>编写了一个<em>EXCEL</em>

因需要,用<em>ASP</em>编写了一个<em>EXCEL</em>

作者:乔山办公网日期:

返回目录:excel表格制作


上传?应该就是个复制的过程吧。。
这种源码网上肯定有的,就是难找。。

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:///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文件中读取数据写入到7a64e58685e5aeb9334SQL数据库
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>


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:///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("数据导入成e799bee5baa6e997aee7ad94e4b893e5b19e364功!");
window.parent.document.location.reload();
history.back();
</script>
</body>
</html>

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网