View Full Version : Exporting MySQL table to Excel file?
ya3
May 7th, 2006, 06:27 AM
Say I had a table with 4 fields - name, surname, email, phone - and I need an easy way for the user to download the table as an Excel spreadsheet (CSV format?), how would I do it?
I basically just need:
name1 surname1 email1 phone1
name2 surname2 email2 phone2
name3 surname3 email3 phone3
Obviously, they need to be arranged into columns in Excel, with each value inside a cell.
What's the easiest way to do this?
Thanks in advance :)
bwh2
May 7th, 2006, 06:34 AM
if you're running phpmyadmin it's very easy. just go to the table you want, then export. pick excel 2000 or csv for ms excel.
or try it some other way (http://www.google.com/search?q=mysql+export+to+excel).
ya3
May 7th, 2006, 08:11 AM
Yeah, I've Googled it already, but there's no harm in asking here ;) Always easier to ask experienced people who've done it before and would know the best ways to do things...
Anyway, I'm actually building a CMS backend for the client to use, so I need to integrate it into my pages, not via phpMyAdmin.
skOOb
May 7th, 2006, 12:20 PM
you can create a tab delimited file. I actually did this for my work. You can create a file named [filename].xls and write to it like a text file using '\t'. Then when the user downloads it, it will open in excel. When they try to save or something, they will get a notice saying that 'excel detected the file as a tab-delimited text file, save as excel spreadsheet?' or something. it worked pretty well.
hth :beer:
bwh2
May 7th, 2006, 01:11 PM
skOOb's method is basically writing a text file and giving it a .xls extension. that would then need to be resaved as an actual excel file, hence the warning message. that would work just as well.
Ankou
May 7th, 2006, 06:58 PM
There's always the option of using the PEAR Spreadsheet_Excel_Writer package - http://pear.php.net/manual/en/package.fileformats.spreadsheet-excel-writer.intro.php
I've used it a number of times when I needed some formatting in the Excel file. Works really well.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.