Solved

out put to an excell spread sheet

Posted on 2006-12-01
11
267 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

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 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/…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

623 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