You are here: Home » PHP » Export Data In Excel In PHP

Export Data In Excel In PHP

23 Flares 23 Flares ×

To export data in excel, Use below php code in your data which you want to export to excel.

<?
$filename ='user_details.xls';

header('Content-type: application/ms-excel');

header('Content-Disposition: attachment; filename='.$filename);

header("Content-Type: application/force-download");

header("Cache-Control: post-check=0, pre-check=0", false);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table border="1" width="100%">
<tr><th>Name</th><th>City</th></tr>
<tr><th>Amar</th><th>Delhi</th></tr>
<tr><th>Suresh</th><th>Surat</th></tr>
<tr><th>Amit</th><th>Patna</th></tr>
<tr><th>Ramesh</th><th>Goa</th></tr>
<tr><th>Pavan</th><th>Varaansi</th></tr>
</table>
</body>
</html>

When you can export dynamic data in php mysql, just create a simple page in which show fatch data and just put.
Below code.

<?
$filename ='user_details.xls';

header('Content-type: application/ms-excel');

header('Content-Disposition: attachment; filename='.$filename);

header("Content-Type: application/force-download");

header("Cache-Control: post-check=0, pre-check=0", false);
?>

About Abhishek Sinha

I am Abhishek and I love to code on PHP.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Scroll To Top
23 Flares Twitter 4 Facebook 3 Google+ 5 StumbleUpon 10 Pin It Share 0 LinkedIn 1 23 Flares ×