Export MYSQL Table to Excel Spreadsheet with the Click of a Link

March 15th, 2005 | Categories: Data | Tags:

PHP Freaks has a great article on exporting a MySQL table to an Excel spreadsheet. Even better, unless you plan on learning what the code does, there is no reason to read the entire article. Here’s what to do to get the export working in 3 steps:

1. Go to the last page and download the ZIP file (halfway down the page in the center)
2. Modify the PHP file you just downloaded with your database login info, and change the “Select Query” to your table name to export
3. Upload it to your server and navigate or link to the newly uploaded Excel Export PHP page.

The following is an example to export the Stats table my blogging software creates to log visitors to this site. Depending on when you stumble on this post, the file may be large or small (I empty it every few weeks).

Click this link to download my Stats table to Excel.

Let me know if it doesn’t work for you, I’ve tested it in IE only. I read some people say you need to have Excel opened before clicking the link, but this isn’t the case so far.

  1. March 15th, 2005 at 14:58
    Reply | Quote | #1

    worked ok for me on xp, xl 2002 and FF v1.

    How was the move?

  2. Mark
    March 15th, 2005 at 18:33
    Reply | Quote | #2

    thanks for the testing. Packing/Unpacking was miserable, the move was smooth. It’s great now that it’s done, It’s my first home I own, I’ve been a long time renter.

    So here’s my slowly developing thought on the send in links/delicious/user submit-comment/ type stuff:

    Each user has their own page where they can collect links or make new posts,

    Each one is located at http://www.automateexcel.com/blogs/username

    They are all aggregated to http://www.automateexcel.com/blogs/all

    Sorta like delicious if you want a linkblog or a blog if you want to type tips. And of course all common tags/categories can be subscribed to. So if you post something tagged winhttp, you can see what other people bookmarked or wrote about for winhttp, and subscribe to winhttp to keep up on future posts for winhtttp.

    And of course there is an RSS feed for each user.

    I might also let the user include an adsense script but rotate mine in every 4th or 5th one, not sure yet (to pay the bills), but only if someone puts up their script first.

    Or something like that, I just like to build the stuff, we’ll see if it’s used.

    Hope things are well in the uk

  3. Mark
    March 15th, 2005 at 18:51
    Reply | Quote | #3

    btw, methods in excel is up to 20 subscribers in bloglines, all looking to see if the feed actually works, lol

  4. August 27th, 2009 at 16:43
    Reply | Quote | #4

    WOW!! Nice tools.. Thanks for shating..

    Mehedi

  5. Rishi
    March 20th, 2010 at 06:39
    Reply | Quote | #5

    Hi guys,

    I’m in urgent need of a PHP script that pulls out the data from mysql table and exports it in excel (formatted file). Pls help.
    Thanks.