argrafic Posted May 2, 2008 Share Posted May 2, 2008 I need to export a MySQL database to Excel. How can I do it? Link to comment https://forums.phpfreaks.com/topic/103881-export-to-excel/ 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 Link to comment https://forums.phpfreaks.com/topic/103881-export-to-excel/#findComment-531749 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. Link to comment https://forums.phpfreaks.com/topic/103881-export-to-excel/#findComment-532088 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? Link to comment https://forums.phpfreaks.com/topic/103881-export-to-excel/#findComment-532092 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 Link to comment https://forums.phpfreaks.com/topic/103881-export-to-excel/#findComment-532113 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. Link to comment https://forums.phpfreaks.com/topic/103881-export-to-excel/#findComment-532116 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 Link to comment https://forums.phpfreaks.com/topic/103881-export-to-excel/#findComment-532185 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.