%@ Language=VBScript %> <% if Request.Form("type")<>"" then set dbConnection = server.CreateObject ("ADODB.Connection") dbConnection.ConnectionString = strConnection dbConnection.Open strSQL = Request.Form("SQL") Set rs = server.CreateObject ("ADODB.Recordset") rs.Open strSQL, dbConnection if Request.Form("records")="page" then ' Pagination: if NOT rs.EOF then mypage = Request.Form("mypage") rs.PageSize = Request.Form("pagesize") maxRecords = cdbl(rs.RecordCount) maxPages=cdbl(rs.PageCount) if cdbl(mypage) > cdbl(maxPages) then mypage = maxpages End IF rs.AbsolutePage = mypage maxrecs=cdbl(rs.pagesize) End IF end if Response.Expires=0 ' prevent caching Response.Buffer=True Server.ScriptTimeout = 120 if Request.Form("type")="excel" then Call ExportToExcel elseif Request.Form("type")="word" then Call ExportToWord elseif Request.Form("type")="xml" then Call ExportToXML elseif Request.Form("type")="csv" then Call ExportToCSV end if rs.Close set rs=Nothing dbConnection.Close set dbConnection = Nothing else %>
<% Response.End end if Sub ExportToExcel Response.ContentType = "application/vnd.ms-excel" Response.AddHeader "Content-Disposition", "attachment;Filename=Results.xls" Response.Write "" Response.Write "