asp中将table表中的数据成功导成excel做法

来源:互联网 发布:人工智能外文参考文献 编辑:程序博客网 时间:2024/06/05 15:44

asp中将table表中的数据成功导成excel做法

我最近刚作了一个项目,该项目的要求是将asp页面中丛书据库中提取的数据直接保存成为excel形式,刚开始我的为此想了好就才最终做了出来,在此和大家共同分享!! 
--------------------------------------- 
脚本如下:<% 
dim Rs_code,Sql_code,Rs_date,Sql_date 
If Request("Op")="Show" Then 
sborder="0" 
sbg1="bgcolor=Black" 
sbg2="bgcolor=White" 
Else 
sborder="1" 
sbg1="" 
sbg2="" 
If Request("Op")="Excel" Then 
Response.ContentType = "application/msexcel" 
Response.AddHeader "Content-disposition","inline; filename=1.xls" 
ElseIf Request("Op")="DownLoad" Then 
Response.ContentType = "application/msexcel" 
FileName="("&Request("sYear")&"-"&Request("sMonth")&")**********(此处为你要做的程序名,自己定义)" 
Response.AddHeader "Content-disposition","attachment; filename="&FileName&".xls" 
End If 
End If 
%> 
在上层的页面中必须给该页面传送:参数:比如QH_TJ_C_imbark.asp?Op=Show 
-------------------------------------------- 
在要转换成excel输出的程序中必须要在如下部分添加: 
<table width="875" border=<%=sborder%> cellspacing="1" cellpadding="1" align="center" <%=sbg1%>> 
--------------------------------------------- 
<tr <%=sbg2%>> 
--------------------------------------------- 
做完以上就绪工作后就可以写你要做的程序了。

0 0
原创粉丝点击