In this article we will tell you how to easily generate MS Excel files using PHP and without the use of any bulky third party code libraries. The idea behind this method is to set the content-type and the content-disposition properties in the header function of PHP to values that produce MS Excel as output. And the data which you want to be filled in your Excel sheet (file) can be simply printed as HTML tables in the script.
Here are the two lines of code in the script which we are talking about:
The only thing you need to change in the above code snippet is replace YOUR_FILE_NAME with the desired filename you want to generate your excel file with. So, if you want to generate an excel sheet with three columns and two rows, just put the above two lines of code at the TOP of your PHP script, followed by an HTML table with three columns and two rows with the data you want in the excel sheet. Here is the code snippet: