asp 小程序代码问题!
<%DimrsInfo,sql,cssprs,ks,actionaction=Request.QueryString("action")ifaction="go"then...
<%
Dim rsInfo,sql,cssprs,ks,action
action = Request.QueryString("action") if action ="go" then
Response.Expires=0
if Request.TotalBytes then
set a=createobject("adodb.stream")
a.Type=1
a.Open
a.write Request.BinaryRead(Request.TotalBytes)
a.Position=0
b=a.Read
c=chrB(13)&chrB(10)
d=clng(instrb(b,c))
e=instrb(d+1,b,c)
set f=createobject("adodb.stream")
f.type=1
f.open
a.Position=d+1
a.copyto f,e-d-3
f.Position=0
f.type=2
f.CharSet="GB2312"
g=f.readtext
f.Close
h=mid(g,instrRev(g,"\")+1,e)
i=instrb(b,c&c)+4
j=instrb(i+1,b,leftB(b,d-1))-i-2
if j <1 then
set f =nothing
set a =nothing
response.write "请确认上传的文件无误<a href='?'>重新上传</a>"
response.end
end if
f.Type=1
f.Open
a.Position=i-1
a.CopyTo f,j
h = Mid(h, InStrRev(h, "filename=""") + 10)
f.SaveToFile server.mappath("/EXCEL/"& h),2
f.Close
set f=Nothing
a.Close
set a=Nothing end if
Set rsInfo = Server.CreateObject("ADODB.RecordSet") Set rsInfo = OpenExcel(Server.MapPath("/excel/a.xls"))
If rsInfo.State<> 1 Then
Response.Write "导入失败1!"
Response.End
End If
If rsInfo.EOF And rsInfo.BOF Then
Response.Write "导入失败2!"
Response.End
End If
If IsNull(rsInfo.Fields(0)) or Trim(rsInfo.Fields(0))="" Then
Response.Write "导入失败3!"
Response.End
End If
If rsInfo.Fields.Count<> 6 Then
Response.Write "导入失败4!"
Response.End
End If
While Not rsInfo.EOF
If Trim(rsInfo.Fields(0))<> "" Then
sql="update TZ_SBGL set 检定周期="&rsInfo.Fields(3)&",检定日期='"&rsInfo.Fields(4)&"',有效日期='"&rsInfo.Fields(5)&"' where 中类='"&rsInfo.Fields(0)&"' and 设备类别='"&rsInfo.Fields(1)&"' and 设备编号="&rsInfo.Fields(2)&""
'response.Write sql set cssprs=Conn.execute(sql)
End If
rsInfo.MoveNext
Wend
rsInfo.Close
Set rsInfo=Nothing
Conn.Close
Set Conn=Nothing
End if %>
以上asp代码实现的功能是上传excel文件到服务器,并根据excel文件中的内容对数据库中指定的表进行修改(html代码和一些不太重要的代码因篇幅原因已省)。我现在的问题是:“ Set rsInfo = OpenExcel(Server.MapPath("/excel/a.xls"))”这句话中a.xls如何替换成直接在file表单中选择的excel文件名。比如说:C:\Users\cc\Desktop\费用导入模板.xls,自动的就替换成了:费用导入模板.xls,而不是上面固定的:a.xls。 展开
Dim rsInfo,sql,cssprs,ks,action
action = Request.QueryString("action") if action ="go" then
Response.Expires=0
if Request.TotalBytes then
set a=createobject("adodb.stream")
a.Type=1
a.Open
a.write Request.BinaryRead(Request.TotalBytes)
a.Position=0
b=a.Read
c=chrB(13)&chrB(10)
d=clng(instrb(b,c))
e=instrb(d+1,b,c)
set f=createobject("adodb.stream")
f.type=1
f.open
a.Position=d+1
a.copyto f,e-d-3
f.Position=0
f.type=2
f.CharSet="GB2312"
g=f.readtext
f.Close
h=mid(g,instrRev(g,"\")+1,e)
i=instrb(b,c&c)+4
j=instrb(i+1,b,leftB(b,d-1))-i-2
if j <1 then
set f =nothing
set a =nothing
response.write "请确认上传的文件无误<a href='?'>重新上传</a>"
response.end
end if
f.Type=1
f.Open
a.Position=i-1
a.CopyTo f,j
h = Mid(h, InStrRev(h, "filename=""") + 10)
f.SaveToFile server.mappath("/EXCEL/"& h),2
f.Close
set f=Nothing
a.Close
set a=Nothing end if
Set rsInfo = Server.CreateObject("ADODB.RecordSet") Set rsInfo = OpenExcel(Server.MapPath("/excel/a.xls"))
If rsInfo.State<> 1 Then
Response.Write "导入失败1!"
Response.End
End If
If rsInfo.EOF And rsInfo.BOF Then
Response.Write "导入失败2!"
Response.End
End If
If IsNull(rsInfo.Fields(0)) or Trim(rsInfo.Fields(0))="" Then
Response.Write "导入失败3!"
Response.End
End If
If rsInfo.Fields.Count<> 6 Then
Response.Write "导入失败4!"
Response.End
End If
While Not rsInfo.EOF
If Trim(rsInfo.Fields(0))<> "" Then
sql="update TZ_SBGL set 检定周期="&rsInfo.Fields(3)&",检定日期='"&rsInfo.Fields(4)&"',有效日期='"&rsInfo.Fields(5)&"' where 中类='"&rsInfo.Fields(0)&"' and 设备类别='"&rsInfo.Fields(1)&"' and 设备编号="&rsInfo.Fields(2)&""
'response.Write sql set cssprs=Conn.execute(sql)
End If
rsInfo.MoveNext
Wend
rsInfo.Close
Set rsInfo=Nothing
Conn.Close
Set Conn=Nothing
End if %>
以上asp代码实现的功能是上传excel文件到服务器,并根据excel文件中的内容对数据库中指定的表进行修改(html代码和一些不太重要的代码因篇幅原因已省)。我现在的问题是:“ Set rsInfo = OpenExcel(Server.MapPath("/excel/a.xls"))”这句话中a.xls如何替换成直接在file表单中选择的excel文件名。比如说:C:\Users\cc\Desktop\费用导入模板.xls,自动的就替换成了:费用导入模板.xls,而不是上面固定的:a.xls。 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询