Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

out put to an excell spread sheet

Posted on 2006-12-01
11
Medium Priority
?
269 Views
Last Modified: 2008-02-01
Hi there,
i have a page that queries some info, is there a way to have a button and export that same exact query to an spread sheet to the user desktop?
Thanks
JSCTECHY
0
Comment
Question by:jsctechy
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 5

Expert Comment

by:cwickens
ID: 18055567
might be easier to create a stored procedure to output a csv file that can be opened with excel.
0
 
LVL 10

Expert Comment

by:KenAdney
ID: 18055683
You can create a table of the data and export it to Excel with

      Response.AddHeader "Content-Disposition", "attachment;filename=mydata.xls"
      Response.ContentType = "application/vnd.ms-excel"
0
 
LVL 9

Expert Comment

by:danataylor
ID: 18055692
Post the page to itself and set the content type to excel if the submit button is pressed.

<form name='MyForm' method='post'>
<%
if request.form("SUBMIT") = "YES" then
  Response.ContentType = "application/vnd.ms-excel"
else
  <input type='submit' name='SUBMIT' value='YES'>
end if
%>
build a table with your data here.  It will go into an Excel spreadsheet if the submit button is pressed.
</form>
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:jsctechy
ID: 18055937
cwickens,
how would i create that store procedure? and how can i call it from my page?
Thanks
0
 
LVL 5

Expert Comment

by:cwickens
ID: 18056064
it would be easier to do what KenAdney and danataylor suggested.  the stored procedure will involve a DTS process as well...for the way I did it.  the end result is actually a CSV file and won't retain any formatting.  With that being said, here is a brief overview of how I did it, after reading what they suggested above, I might go back and undo the *&^)# I created below:

the stored procedure will look something like:
CREATE PROCEDURE dbo.mt_sams_output
 AS

exec xp_cmdshell 'dtsrun.exe /Stoolkitdata /E /Nmt_crra_output'
GO

the DTS Process will have 3 parts to it, the connection to the DB, the command to create the output and then a copy function to override the existing file made by the previous user who requested the same:
'**********************************************************************
'  Visual Basic ActiveX Script
'************************************************************************

Function Main()
      Const OverwriteExisting = TRUE

      Set objFSO = CreateObject("Scripting.FileSystemObject")
      objFSO.CopyFile "F:\*yourDirectoryStructure*\awame125.dat" , "\\*yourDirectoryStructure*\", OverwriteExisting

      Main = DTSTaskExecResult_Success
End Function

Like I said, I like thier versions better...
0
 
LVL 1

Author Comment

by:jsctechy
ID: 18056128
danataylor, KenAdney
<%response.ContentType="application/vnd.ms-excel"%>
This example will open an Excel spreadsheet in a browser (if the user has Excel installed):
 but i don't want to display it or even have to write a table for it, i just want to click and create a file on their desktop thats all.

is there a way to do it?
what i thinking seems i have all the values of the query on my conn.Execute(mySQL) them from there i can do something else with it like output it to another directory no?
0
 
LVL 9

Expert Comment

by:danataylor
ID: 18056294
Not sure that is possible with the current state of browser security settings.  If it were possible, then a malicious web page could drop any file onto your desktop.  At any rate it would require enabling ActiveX on the client and that's not recommended either.
0
 
LVL 1

Author Comment

by:jsctechy
ID: 18056313
well that is true
so there is not way of have mi idea or task done?
0
 
LVL 1

Author Comment

by:jsctechy
ID: 18056318
ok so how about display it the spreadsheet in the screen but no have to write the table on the actual asp page?
0
 
LVL 9

Accepted Solution

by:
danataylor earned 1000 total points
ID: 18056379
<form name='MyForm' method='post'>
<%
if request.form("SUBMIT") = "YES" then
  Response.ContentType = "application/vnd.ms-excel"

Put the table here and the user will only see the submit button when the page loads.  After they hit the button the Excel spreadsheet will pop up with the cells filled in with the table data.  You would also need to retrieve the data from somewhere - a DB or something unless all the cells are static info.

else
  <input type='submit' name='SUBMIT' value='YES'>
end if
%>
</form>

0
 
LVL 1

Author Comment

by:jsctechy
ID: 18056447
can you show me this with an example from the Northwind SQL database
how would you create the actual table and everything?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question