1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

ASP to EXCEL , Problem, reload, refresh

Discussion in 'C#' started by devloy, May 31, 2008.

  1. #1
    Hi,

    I found ways how to write EXCEL files from ASP, but I still have problems.

    1- on localhost IE 7.0 keeps reloading the page
    2- it forgets to output it as excel file instead starts saving it as ASP file (with xls extenion however the file can be opened in EXCEL as well)

    here is a sample code:

    <%@ Language=VBScript %>
    <!--#include file="../includes/dbSetting.asp" -->
    <%
    Response.ContentType = "application/vnd.ms-excel"

    Dim dbConn, dbRSet

    mySQL = "SELECT cID, cTitle FROM course_tbl"
    call dbRead(mySQL)

    crsRec = dbRSet.RecordCount
    crsData = dbRSet.GetRows()

    Const tmpcID = 0
    Const tmpcTitle = 1
    %>
    <HTML>
    <Head></head>
    <BODY>
    <font face="Arial, Verdana, Helvetica, sans-serif">
    <table>
    <tr>
    <td width="25%" valign="top" bgcolor="#2F7BB9"><strong><font color="#FFFFFF" size="3" face="Verdana, Arial, Helvetica, sans-serif">Course ID</font></strong></td>
    <td width="75%" valign="top" bgcolor="#2F7BB9"><strong><font color="#FFFFFF" size="3" face="Verdana, Arial, Helvetica, sans-serif">Course Title</font></strong></td>
    </tr>
    <%For i=0 to crsRec - 1 %>
    <tr>
    <td width="25%" valign="top"><font size="3" face="Verdana, Arial, Helvetica, sans-serif"><%= crsData(tmpcID,i)%></font></td>
    <td width="75%" valign="top"><font size="3" face="Verdana, Arial, Helvetica, sans-serif"><%= crsData(tmpcTitle,i)%></font></td>
    </tr>
    <%next%>
    </table>
    </font>
    </BODY>
    </HTML>
    <%
    call closeRC() 'Closes database connetion and clears the record set
    %>
     
    devloy, May 31, 2008 IP
  2. IrieDev

    IrieDev Active Member

    Messages:
    156
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #2
    Try adding the second line below with the name of your Excel file, in this case projects.xls:

    Response.Contenttype="application/vnd.ms-excel"
    Response.AddHeader "content-disposition","attachment;filename=projects.xls"
     
    IrieDev, Jun 5, 2008 IP