Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7439831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:45:44+00:00 2026-05-29T10:45:44+00:00

I’m trying to set up a page that downloads a sql table and gives

  • 0

I’m trying to set up a page that downloads a sql table and gives the user a prompt to save it to excel. This will be used in the horrible thing called IE7.

The problem is that instead of downloading the file that I know exists, it generates the asp page into the xls file, and titles it “DataManager.xls”. So if I open that, I get the header bar of the asp page, and if I leave out the resonse.end I get the page body and footer. But all my research says this code should be downloading an existing file, not creating one.

None of my response.write tracers work. But strSQL is being run properly, because that generates the file.

        dim strSQL

    if(Request.QueryString("submitbutton") = "Download") then
        dim fn
        dim FPath
        strSQL = "EXECute [TABLE2EXCEL] 'S007\SQLSRV','" & UCase(request.QueryString("SelTABLE")) & "','" & UCase(request.QueryString("SelTABLE")) & "','" & Replace(Request.ServerVariables("LOGON_USER"),"CORP\","") & "'"
        fn = cnt.execute(strSQL)

        response.write strSQL
        response.write fn
        response.write FPath

         Response.ContentType = "application/vnd.ms-excel" ' arbitrary 
        FPath = fn 
        Response.AddHeader "Content-Disposition","attachment; filename=ASSOCIATEROSTERFeb102012909AMNBKMZEJ.xls" '& fn 

        Set adoStream = CreateObject("ADODB.Connection") 
        adoStream.Open() 
        adoStream.Type = 2
        adoStream.LoadFromFile("\\s007\folder\DataFactory\ASSOCIATEROSTERFeb102012909AMNBKMZEJ.xls")'(FPath) 
        Response.BinaryWrite adoStream.Read() 
        adoStream.Close 
        Set adoStream = Nothing 
Response.End 
end if

And just to be complete on data, here’s my sql code:

ALTER procedure [dbo].[TABLE2EXCEL]
(
    @db_name    varchar(100),
    @table_name varchar(100),   
    @file_name  varchar(100),
    @NBK    varchar(10)
)
as

--Generate column names as a recordset
declare @columns varchar(8000), @sql varchar(8000), @data_file varchar(100)

select 
    @columns=coalesce(@columns+',','')+column_name+' as '+column_name 
from 
    information_schema.columns
where 
    table_name=@table_name
select @columns=''''''+replace(replace(@columns,' as ',''''' as '),',',',''''')

declare @TimeStamp varchar(50)
SELECT @TimeStamp = Replace(Replace(CAST(CONVERT(datetime,getdate())as varchar),':',''),' ','') + @NBK

print @TimeStamp

--Set folder for output file
set @file_name = '\\s007\folder\DataFactory\' + @file_name + @TimeStamp + '.xls'

--Create a dummy file to have actual data
select @data_file='\\s007\folder\DataFactory\data_fildat' + @TimeStamp + '.xls'--substring(@file_name,1,len(@file_name)-charindex('\',reverse(@file_name)))+'\data_filez.xls'
print @data_file
--Generate column names in the passed EXCEL file
set @sql='exec master..xp_cmdshell ''bcp " select * from (select '+@columns+') as t" queryout "'+@file_name+'" -c -S S007\SQLSRV -U userlogin -P passwordisbestpassword -k'''
exec(@sql)

--Generate data in the dummy file
set @sql='exec master..xp_cmdshell ''bcp " select * from '+@table_name+'" queryout "'+@data_file+'" -c  -S S007\SQLSRV -U userlogin -P passwordisbestpassword -k'''

exec(@sql)
PRINT @sql 
PRINT @data_file 

--Copy dummy file to passed EXCEL file
set @sql= 'exec master..xp_cmdshell ''type "'+@data_file+'" >> "'+@file_name+'"'''
exec(@sql)

--Delete dummy file 
set @sql= 'exec master..xp_cmdshell ''del '+@data_file+''''
exec(@sql)


return @file_name
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:45:44+00:00Added an answer on May 29, 2026 at 10:45 am

    Usually this is done by generating a regular HTML table with the data in it and sending out the Excel MIME type.

    Response.ContentType = "application/vnd.ms-excel"
    

    (then output the HTML table)

    See this question for an example: Export data to excel file from Classic ASP failing

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.