Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

From Recordset to Spreadsheet 1

Status
Not open for further replies.

disord3r

Programmer
Apr 12, 2002
189
0
0
US
I currently have a script that pulls a little bit of data from a database and displays it on screen. On this results screen, I'd like to give my users an option to save the data they're seeing to a website.

What I had in mind was a link on the results screen, created from the path_info and query_string envrionment varialbes, that makes another query to reproduce what they're seeing on the screen. This link would pass an additional variable with the query string to let the script know it needs to create a spreadsheet on this time around.

The link seems to be working as I would expect (data does not display on the screen like it did the first time around), but I'm not sure how to get that recordset data into a spreadsheet. I'd prefer to have it just launch excel, or at least ask if they want to save or open the sheet, rather than displaying the spreadsheet within Internet Explorer.

Anyone got any suggestions?
 
What you need to do is send the type of file you want the Explorer to handle, the first line in your stream would have to be

Response.ContentType = "application/vnd.ms-excel"

There's a pretty good and complete tutorial on this at


You might want to check it out. The guy even explains how to create calculated cells from the values you are sending to the page.
 
Okay, I've gotten a little close, but I'm not quite there yet.

I have two asp scripts now; one that is used to display the data on screen along with the link, and the second one which is loaded when the link is clicked.

The first one works fine, and all the data is coming up on the screen like I want it to. When I click the link for view it in spreadsheet form, I get a pause, then a little dialog box that says it's transferring data (just like it did in the example on the aspalliance page), but then an error. The error says:

Microsoft Excel cannot access the file 'http://[full url of the script]?[all my query string data]'. There are several reasons etc etc etc...

Thinking that it might actually be trying to use the query string data as part of the filename that it was attempting to 'access', I tried to access the second script directly. It does the same thing.

Any help would be appreciated. I'm off to fool around with that a little bit.
 
Got it working. The code in the link you gave me was not the problem. I was accessing some of my queryqtring data with request.form. :)

The only thing I have left to do is find out how to change the name that is used for the worksheet. By default, it uses the script name and the querystring. This is not desireable.

Thanks grtfercho.
 
Hopefuly this wont get cut off...

<html xmlns:eek:=&quot;urn:schemas-microsoft-com:eek:ffice:eek:ffice&quot;
xmlns:x=&quot;urn:schemas-microsoft-com:eek:ffice:excel&quot;
xmlns=&quot;
<head>
<meta http-equiv=Content-Type content=&quot;text/html; charset=windows-1252&quot;>
<meta name=ProgId content=FrontPage.Editor.Document>
<meta name=Generator content=&quot;Microsoft FrontPage 4.0&quot;>
<link rel=File-List href=&quot;./Book1_files/filelist.xml&quot;>
<link rel=Edit-Time-Data href=&quot;./Book1_files/editdata.mso&quot;>

<xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>test2</x:Name>
</x:ExcelWorksheet>
<x:ExcelWorksheet>
<x:Name>test3</x:Name>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml>

</head>

<body>

<table border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; style=&quot;border-style: ridge; border-width: 1&quot;>

<tr>
<td>blaw 1</td>
<td>blaw 2</td>
</tr>
<tr>
<td>blaw 3</td>
<td></td>
</tr>


</table>

</body>

</html>




As you can see there is some xml you can use to set the work sheet names notice the values test2 and test3
 
trinity -

I have been trying to figure out how to write data to the second worksheet (see thread426-536425). I know how to create it and give it a title, but how do you actually put data into the cells?

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top