asp导出excel

climix 2007-08-24 11:14:18
前面是导出按钮:
<input type=button name=submit value="导出EXCEL" onclick="javascript:window.open('excel.asp','new','scrollbars=1','width=200')" >
怎么把参数传递过来,tiaojian,tiaojian_name,leixing三个:
<select name='tiaojian' style="BACKGROUND-COLOR: #ffffff; COLOR: #19b460; FONT-FAMILY: 宋体; FONT-SIZE: 9pt; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-color:#198b446">
<option value='hetong_no'>合同号</option>
<option value='supplier'>供应商</option>
<option value='need'>需求方</option>
<option value='input_name'>合同经办人</option>
<option value='bumen'>分组</option>
<option value='product_name'>加工劳务名称</option>
<option value='huo_no'>PO#</option>
<option value='color_no'>款号</option>
<option value='per'>加工单价</option>
</select></td>

<td>
<font size=2 color=red><b>查询类型</b></font>
<select name='leixing' style="BACKGROUND-COLOR: #ffffff; COLOR: #19b460; FONT-FAMILY: 宋体; FONT-SIZE: 9pt; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-color:#198b446">
<option value='模糊查询'>模糊查询</option>
<option value='精确查询'>精确查询</option>
<option value='区间'>区间</option>
</select>
<input type=text size=10 name=tiaojian_name>
接下来就是excel.asp了。
怎么读取tiaojian,tiaojian_name,leixing 三个参数,另外主程序不知道有没有问题,我贴出来:
<!--#include file="conn.asp"-->
<%response.contenttype="application/vnd.ms-excel"%>
<%
dim s,sql,filename,fs,myfile,x
dim tiaojian,tiaojian_name,leixing
dim cstr1,cstr2,cstr3,cstr4
Set fs = server.CreateObject("scripting.filesystemobject")
'--假设你想让生成的EXCEL文件做如下的存放
filename = Server.MapPath("waixie.xls")
'--如果原来的EXCEL文件存在的话删除它
if fs.FileExists(filename) then
fs.DeleteFile(filename)
end if
'--创建EXCEL文件
set myfile = fs.CreateTextFile(filename,true)

cstr1=request.querystring("tiaojian")
cstr2=request.querystring("tiaojian_name")
cstr3=request.querystring("leixing")
if cstr3="精确查询" then
cstr4="="
else
cstr4=" like "
cstr2="%"&cstr2&"%"
end if
if cstr2<>"" then
Set rs= Server.CreateObject ("ADODB.RecordSet")
sql = "select * from view_hetong_1 where "&cstr1&cstr4&"'"&cstr2&"' order by ht_date desc"
rs.open sql,conn,1,3
else
response.write"<td valign='center'> <font color=blue size='4'>查询内容没有填写,请<a href='waixie_manager.asp'>返回</font></a></td>"
response.end
end if
if not rs.EOF and not rs.BOF then

dim trLine,responsestr
strLine=""
For each x in rstData.fields
strLine = strLine & x.name & chr(9)
Next

'--将表的列名先写入EXCEL
myfile.writeline strLine

Do while Not rs.EOF
strLine=""

for each x in rs.Fields
strLine = strLine & x.value & chr(9)
next
myfile.writeline strLine

rs.MoveNext
loop

end if

Response.Write "生成EXCEL文件成功,点击<a href="/"waixie.xls"" target=""_blank"">下载</a>!"

rs.Close
set rs = nothing
Conn.Close
Set Conn = nothing
%>


...全文
793 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
小官 2011-08-18
  • 打赏
  • 举报
回复
开发语言:ASP,开发环境:dreamweaver

从sql 2000数据库查询出的结果以表格的形式显示在页面上,却不知道怎么通过导出按钮导入excel ? 哪位大侠如果有代码还请不吝指教下?如果有代码可以发给我吗?287168917@qq.com,不胜感激~!
wrswrs 2008-03-15
  • 打赏
  • 举报
回复
近日在用asp把access数据库的查询结果导出为excel文件时,出现一点问题,因为有一个字段是身份证号码,在导出的excel文件中,所有身份证号后3位全部变成0了!真是郁闷啊!网上查了一下才知道是excel默认的数字格式是"常规",只能正常显示输入的11位数字,超过11位就用科学记数法显示了。
为了解决这个问题,我只能把查询的数据标识成文本型数据,下面是部份代码:
<%
'导出到excel
set rs = server.createobject("adodb.recordset")
sqlstr="select * from tabname where"&searhsql '查询语句
rs.open sqlstr,oconn,1,3
%>
<%set fs = server.createobject("scripting.filesystemobject")
'存放文件
filename="info.xls"
temp=filename
filename=request.servervariables("appl_physical_path")&"\"+filename
'删除存在的excel文件
'if fs.fileexists(filename) then
'fs.deletefile(filename)
'end if
'-创建excel文件
set myfile = fs.createtextfile(filename,true)
dim strline,responsestr
strline=""
for each x in rs.fields
strline= strline & x.name & chr(9)
next
'将表的列名先写入excel
myfile.writeline strline
while not rs.eof
strline=""
for each x in rs.fields
'这里把数据标识成文本类型
strline= strline & "="""&x.value &""""& chr(9)
next
'将表的数据写入excel
myfile.writeline strline
rs.movenext
wend
link="<a href=\" & temp & " title=将数据保存至eecel表中><font color=red><b>导出excel文件</b></font></a>"
response.write link
set myfile = nothing
set fs=nothing
rs.close
%>
这是我改进过的代码,实例源代码下载地址:http://www.ewcode.com/soft/1/8/2008/2008031410746.html
taochunsong 2007-08-25
  • 打赏
  • 举报
回复
你的方法是去写一个excel文件

告诉你另外一个方法
规则的表格

就是以excel方式打开asp文件的
只用一个语句就可以了阿
本页面链接到另一个页面2.asp
把原来的页面复制一份改名叫2.asp
在前面加上
<% response.contenttype="application/vnd.ms-excel"%>
即可
http://www.laotao.cn/article.asp?id=376

什么都不能 2007-08-24
  • 打赏
  • 举报
回复
js把查询内容连成参数字符串加到链接后面,也就是用get传参
chloe 2007-08-24
  • 打赏
  • 举报
回复
把三个条件放到一个form中,再提交form到excel.asp就可以了。
cow8063 2007-08-24
  • 打赏
  • 举报
回复
提交 表单呀
<input type=button name=submit value="导出EXCEL" onclick="javascript:window.open('<%=xxxx%>','new','scrollbars=1','width=200')" >

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧