I'm need of downloading my table to excel at the end of every single month. How could i do that? Please let me know that with some graspable example or link. I'll so grateful.
CSV (comma seperated values) format is an option, You can import this format in excel or any spreadsheet application. <?php $data[] = 'id,first_name,last_name'; $result = mysql_query('SELECT * FROM table WHERE 1=1'); while ($row = mysql_fetch_assoc($result)) $data[] = $row['id'] . ',' . $row['first_name'] . ',' . $row['last_name']; print implode($data, "\r\n"); ?> PHP:
Thanks man. I can understand what you're trying to say. But how can i download that? I need to put just one link in my project after clicking, that will download the respective table into csv.
Put this at the beginning of the code: header('Content-Type: application/csv'); header('Content-Disposition: attachment; filename=example.csv'); header('Pragma: no-cache'); PHP:
How can we connect the former coding with the current header coding it seems to be no connection with both of them. Sorry i actually can't grasp it. please let me know.
No need man further information. Thanks very much I took a trial with this. It works great. Again thank you very much...
I've got an another problem. When i click download button, the html coding are also downloaded within that excel sheet if i use html tags in that php page. What should i do now to get rid of html tags in excel? Thank. Hussain
Put the above code at the beginning of your file (before printing anything in page). After printing the csv results end up the process using "exit" or "die()": exit; PHP:
Thanks I've one function in which i wrote the csv coding. But before csv coding i also need to write some html coding here. <?php ...... public function excel() { header('Content-Type: application/csv'); header('Content-Disposition: attachment; filename=example.csv'); header('Pragma: no-cache'); } ........?> this function is called when my all process are finished and then all details are stored in excel i took a trial here all details are stored but in addition the tags that i used in that php page are also displayed in that excel sheet? What should i do now?
In this case you need to put the csv exporting codes to another file like "export.php", and redirect the main file to export.php when processing and storing is done. PHP does not allow change headers when anything is printed in the result.
So noway for this problem rather than separating the csv coding into a new file. Ok dude... Thank you very much.
Hi man Another simple doubt Can i apply some colors to respective cell that i want to fill if its feasible, then please let me know...
Anyone out here to help me? Please tell me how to apply colors when i download excel sheet from table. Thanks.
CSV format does not support any text formating. You need a library to export output as excel spreadsheet. Try PHPExcel.
You mean i just remove the csv coding and try to output my table as properly excel and also apply color to respective cells that we wanted.
header('Content-Type: application/xls'); header('Content-Disposition: attachment; filename=example.xls'); header('Pragma: no-cache'); The keyword xls in first and second line output our details as excel sheet? Thanks
I think PHPExcel will do this. Anyway: header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); header("Content-Disposition: attachment;filename=\"filename.xlsx\""); header("Cache-Control: max-age=0"); PHP:
If you are using phpmyadmin you will see that its allowing you to export to csv file and it can be used in excel directly