Simple excel export using PHP
Step 1. Add the below header(code) in excel.php file.
header("Content-type: application/xls");
header("Content-Disposition: attachment; filename=user.xls");
header("Pragma: no-cache");
header("Expires: 0");
Step2 : Construct a HTML table and assign to a php variable.
$test="<table cellspacing='0' cellpadding='0' border='1'>
<tr>
<td><b>Email</b></td>
<td><b>Created</b></td>
<td><b>First name</b></td>
<td><b>last name</b></td>
<td><b>Sign up</b></td>
</tr>";
$test .="<tr>
<td><b>abc@gmail.com</b></td>
<td><b>17th Jan 2013</b></td>
<td><b>Romel</b></td>
<td><b>Christopher</b></td>
<td><b>1</b></td>
</tr></table>";
Step 3 : Print the variable in the file.(don't add exit after echo)
echo $test;
exit;
This code will download a excel file with the name "user.xls"
header("Content-type: application/xls");
header("Content-Disposition: attachment; filename=user.xls");
header("Pragma: no-cache");
header("Expires: 0");
Step2 : Construct a HTML table and assign to a php variable.
$test="<table cellspacing='0' cellpadding='0' border='1'>
<tr>
<td><b>Email</b></td>
<td><b>Created</b></td>
<td><b>First name</b></td>
<td><b>last name</b></td>
<td><b>Sign up</b></td>
</tr>";
$test .="<tr>
<td><b>abc@gmail.com</b></td>
<td><b>17th Jan 2013</b></td>
<td><b>Romel</b></td>
<td><b>Christopher</b></td>
<td><b>1</b></td>
</tr></table>";
Step 3 : Print the variable in the file.(don't add exit after echo)
echo $test;
This code will download a excel file with the name "user.xls"
Comments