myharshdesigner Posted May 15, 2007 Share Posted May 15, 2007 how to create excel CSV file for download ? pl tell me the code or tutorial any help ? Quote Link to comment https://forums.phpfreaks.com/topic/51425-excel-csv-file-for-download/ Share on other sites More sharing options...
marf Posted May 15, 2007 Share Posted May 15, 2007 csv file is fairly easy to create with PHP. And of course Excel can open any csv file quite easily. The data won't look pretty, but that's not what it's supposed to do. Um, if theres a tutorial on EXACTLY what you want to do? I'm not sure. But you will want to become familiar with PHP's fopen, and all that for file handling. And explode() and implode() you will probably use. The information your saving to the csv files is from MySQL or some other source, and I'm assuming you can read from there. Quote Link to comment https://forums.phpfreaks.com/topic/51425-excel-csv-file-for-download/#findComment-253276 Share on other sites More sharing options...
utexas_pjm Posted May 15, 2007 Share Posted May 15, 2007 No need to waste space on your server's HD by saving a file: <?php header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename='foo.csv'"); $data="col1, col2, col3, \n"; echo $data; ?> Best, Patrick Quote Link to comment https://forums.phpfreaks.com/topic/51425-excel-csv-file-for-download/#findComment-253288 Share on other sites More sharing options...
myharshdesigner Posted May 15, 2007 Author Share Posted May 15, 2007 if suppose i have a mysql database and i want to get data from mysql & then make CSV file for download so now how can i do that ? can u help me out ? No need to waste space on your server's HD by saving a file: <?php header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename='foo.csv'"); $data="col1, col2, col3, \n"; echo $data; ?> Best, Patrick Quote Link to comment https://forums.phpfreaks.com/topic/51425-excel-csv-file-for-download/#findComment-253488 Share on other sites More sharing options...
redbullmarky Posted May 15, 2007 Share Posted May 15, 2007 myharshdesigner, please provide the code you have already tried. if you wish for someone to write the complete code for you, then try posting for paid help in the Freelance board. A Google search for PHP and CSV will provide you with the resources - there's no point getting code if you're not going to be able to understand it, as you'll end up with tonnes more problem down the line. Quote Link to comment https://forums.phpfreaks.com/topic/51425-excel-csv-file-for-download/#findComment-253499 Share on other sites More sharing options...
jitesh Posted May 15, 2007 Share Posted May 15, 2007 <?php $data = ""; $row = 'first value,'; $row .= 'second value,'; $row .= 'third value'; $data .= $row."\n"; $row = 'fourth value,'; $row .= 'fifth value,'; $row .= 'sixth value'; $data .= $row."\n"; // Output the headers to download the file header("Content-type: application/x-msdownload"); header("Content-Disposition: attachment; filename=log.csv"); header("Pragma: no-cache"); header("Expires: 0"); echo $data; ?> Quote Link to comment https://forums.phpfreaks.com/topic/51425-excel-csv-file-for-download/#findComment-253513 Share on other sites More sharing options...
jitesh Posted May 15, 2007 Share Posted May 15, 2007 header("Content-type: application/x-msdownload"); instead try this header("Content-type: text/x-csv"); Quote Link to comment https://forums.phpfreaks.com/topic/51425-excel-csv-file-for-download/#findComment-253521 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.