argrafic Posted May 2, 2008 Share Posted May 2, 2008 I need to export a MySQL database to Excel. How can I do it? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted May 2, 2008 Share Posted May 2, 2008 Do you have phpMyAdmin installed? If so, use the export option to create a CSV for Excel file. If you don't, let me know and I can dig up some PHP -> Excel scripts Quote Link to comment Share on other sites More sharing options...
argrafic Posted May 2, 2008 Author Share Posted May 2, 2008 thanks. the way it's supposed to work is that there are reports i will determine with php but the user can just export to excel the whole database. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 2, 2008 Share Posted May 2, 2008 it depends on whether you're exporting to .xls or .xlsx. which version of Excel are you targeting? Quote Link to comment Share on other sites More sharing options...
argrafic Posted May 2, 2008 Author Share Posted May 2, 2008 .xls, most users have up to office 2003 Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 2, 2008 Share Posted May 2, 2008 okay, you may be able to do it the easiest way: output a tab-delimited file with a .xls extension something like: $data = ""; while (list($field1_val, $field2_val, $field3_val) = mysql_fetch_row($result)) { $data .= "$field1_val\t$field2_val\t$field3_val\n"; } then write $data to a file with a .xls extension. if you need to format cells and stuff, you'll probably want to look into this Pear thing: http://pear.php.net/package/Spreadsheet_Excel_Writer/redirected I use it with great results. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted May 3, 2008 Share Posted May 3, 2008 Straight from the MySQL manual: SELECT a,b,a+b INTO OUTFILE '/tmp/result.txt' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM test_table; Creates a csv file that is readable by Excel. http://www.mysql.com/select#id1949480 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.