asp导出excel
前面是导出按钮:
<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
%>