Solved

out put to an excell spread sheet

Posted on 2006-12-01
11
265 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 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