How can we generate Excel File or CSV in PHP code on click

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 64
Joined: Thu Mar 14, 2013 6:10 am

Tue Jun 25, 2013 5:39 am


I want to create a Excel or csv file when the user clicks on button in PHP, is there any way to do this

php-forum Super User
php-forum Super User
Posts: 1803
Joined: Thu Mar 10, 2011 5:07 pm

Tue Jun 25, 2013 6:51 am

use something like this:

Code: Select all

header("Content-Type:   application/; charset=utf-8");
header("Content-Disposition: attachment; filename=somefile.xlsx"); 
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
echo "your text that you want to appear in excel file"; 
I have not tested this but it is something like this.

Post Reply