Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

out put to an excell spread sheet

Posted on 2006-12-01
11
Medium Priority
?
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

715 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