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

2013 年 8 月 11 日4270

  脚本如下:<%

  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 border=<%=sborder%> cellspacing="1" cellpadding="1" <%=sbg1%>>

  ---------------------------------------------

  <tr <%=sbg2%>>

  ---------------------------------------------

  做完以上就绪工作后就可以写你要做的程序了。

0 0