Php to Excel

This is one sweet code to export your variables and pass it on to a downloadable excel file. As of now i am working on an resume maintenance project and that needs this aspect. I googled for the simplest and efficient code.

I use a wamp localhost and faced warnings with all classes and codes that use the fopen(xls://FILENAME) format. This particular code was so cool enough to not read and open any existing file but just provide a  new file that you’ll name at runtime and download.

Its  more like writing the file on flyby!!

If you were one among those who googled for excel to php/php to excel/php write excel files/write excel files in php  and came here, trust me its a standalone simple code below. Just copy paste and it will start working.


header(“Content-type: application/x-msdownload”);
header(“Content-Disposition: attachment; filename=extraction.xls”);
header(“Pragma: no-cache”);
header(“Expires: 0”);
print “$header\n$data”;


The code is pretty self explanatory with /t for column break and \n for line break.



One thought on “Php to Excel

  1. hi madan….!!

    from the past two days i am visiting your blog…..too good dear…nice postings…!!

    the fact is i have just developed a interest in robotics after attending a workshop…m planning to make some bots….and regarding the same found ur blog worthy..!!

    i hav added ur blog to my blog site..

    will bother you dear, when i get some probs…..!!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s