Solved

out put to an excell spread sheet

Posted on 2006-12-01
11
262 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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 500 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now