Asp classic 下载Excel在ASP中无法正常工作

Asp classic 下载Excel在ASP中无法正常工作,asp-classic,Asp Classic,我是ASP新手。我需要编写一个脚本,以便在ASP中下载Excel。我尝试过,但它正在下载整个页面内容,但我需要从数据库下载表 这是我的密码: <%@Language="VBScript"%> <form name="form1" id="form1" method="post"> <input type="hidden" name="action" value="sel"> <table> <

我是ASP新手。我需要编写一个脚本,以便在ASP中下载Excel。我尝试过,但它正在下载整个页面内容,但我需要从数据库下载表

这是我的密码:

     <%@Language="VBScript"%>
     <form name="form1" id="form1" method="post">
     <input type="hidden" name="action" value="sel">
     <table>
     <tr>
     <td><input type="submit" name="submit" id="submit" value="Download Excel"></td>
     </tr>
     </table>
     Hello World
     <%
     action = Request.Form("action")

     If action="sel" Then
     Response.ContentType = "application/octet-stream"
     Response.ContentType = "application/vnd.ms-excel"

     SET Conn = Server.CreateObject("ADODB.Connection")
     Conn.OPEN "PROVIDER=SQLOLEDB;DATA  SOURCE=10.1.1.1;UID=sa;PWD=root;DATABASE=Student"
     dim Conn,Rs
     set Rs=server.createobject("ADODB.recordset")
     Rs.open "SELECT * FROM studentdetails",Conn
     Response.AddHeader "Content-Disposition", "attachment; filename=xl_data.xls"
     %>
   <TABLE BORDER=1>
       <TR>
       <%
       j = 2
       For i = 0 to RS.Fields.Count - 1
       %>
       <TD width="18"><B>
       <% = RS(i).Name %></B></TD>
       <% Next %>
       <TD width="42"></TD>
       <TD width="53"></TD>
       </TR>
       <%
       Do While Not RS.EOF
       %>
      <TR>
      <% For i = 0 to RS.Fields.Count - 1
       %>
      <TD VALIGN=TOP><% = RS(i) %></TD>
      <% Next %>
      </TR>
      <%
      RS.MoveNext
      j = j + 1
      Loop
      RS.Close
  End If
      %>
      </TABLE>

你好,世界
在这个程序中,我在下载的同时加入了Hello World line,它也在下载。所以请给我一些建议。提前谢谢。

替换

Response.ContentType = "application/octet-stream"


否则,您将表单和表格发送到Excel

您可能需要一个带有表单的页面来调用此页面(没有表单)。对不起,我不明白。请更清楚地告诉我@贾努斯·贾辛基
Response.Clear