Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Download database as Excel doc?

Download database as Excel doc?
Thread Tools
Posting Junkie
Join Date: Jun 2001
Location: Washington DC
Status: Offline
Reply With Quote
Feb 11, 2005, 03:35 PM
 
I have a website that uses a MySQL database to create a table of data on a webpage. My users want to be able to download the data as an Excel spreadsheet. While I'm pretty sure that this specifically is impossible without cooperation from Microsoft, I've managed to write a script that dynamically creates a tab-delimited text document which can then be imported as an Excel spreadsheet.

This may be the closest that is possible to what they want, but does anyone know if I can do better?

Also, for some reason, when you try to download the file in Safari it wants to change the file extension. The file on the server is called HHP_VPR.txt (though it's actually a PHP script that generates the document on the fly), when you try to download it in Safari it renames it to HHP_VPR.html and won't let you change it. Obviously once it's downloaded you can change the extension back to .txt, but it's still a pain and shouldn't be necessary. It doesn't do this in any other browser. I assume this probably has something to do with the fact that the document isn't actually a text file and is a php file instead, but is there some way to stop it from doing this?
     
Clinically Insane
Join Date: Nov 1999
Status: Offline
Reply With Quote
Feb 11, 2005, 04:11 PM
 
What language are you using? This page has some documentation and code, but how useful that is will depend somewhat on what language you are using.

That said, if you can get the data into tab-delimited text already, then adapting it to any of these should (hopefully) not be too painful.
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
     
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Feb 11, 2005, 06:11 PM
 
Millenium: Presumably he's using PHP, from this line: "though it's actually a PHP script'

Originally posted by nonhuman:
I have a website that uses a MySQL database to create a table of data on a webpage. My users want to be able to download the data as an Excel spreadsheet. While I'm pretty sure that this specifically is impossible without cooperation from Microsoft, I've managed to write a script that dynamically creates a tab-delimited text document which can then be imported as an Excel spreadsheet.

This may be the closest that is possible to what they want, but does anyone know if I can do better?
Well, I remember briefly looking at the same sort of problem a while back and settled for a cvs file, rather than tab delimited, since excel handles these very well and they're easy to work with. Still, presumably there's a better solution.

Originally posted by nonhuman:
Also, for some reason, when you try to download the file in Safari it wants to change the file extension. The file on the server is called HHP_VPR.txt (though it's actually a PHP script that generates the document on the fly), when you try to download it in Safari it renames it to HHP_VPR.html and won't let you change it. Obviously once it's downloaded you can change the extension back to .txt, but it's still a pain and shouldn't be necessary. It doesn't do this in any other browser. I assume this probably has something to do with the fact that the document isn't actually a text file and is a php file instead, but is there some way to stop it from doing this?
Tried setting the Content-type header?
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
Posting Junkie
Join Date: Jun 2001
Location: Washington DC
Status: Offline
Reply With Quote
Feb 11, 2005, 07:47 PM
 
Originally posted by Black Book:
Well, I remember briefly looking at the same sort of problem a while back and settled for a cvs file, rather than tab delimited, since excel handles these very well and they're easy to work with. Still, presumably there's a better solution.[/b]
Ooh, I'll look into that.

Tried setting the Content-type header?
AHA! I bet that's it!

Thanks!
     
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Feb 12, 2005, 09:10 AM
 
Yep, try the 'Excel Spreadsheet Writer' class from pear.php.net/packages/

It takes a little getting used to, but the results are pretty solid. Haven't had a complaint from any PC users, either.
Computer thez nohhh...
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:09 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2