Wednesday, April 27, 2016

Custom download to excel using php


 <?php
 $content="<table><tr><td style='color:red;background-color:green;'>created by bikash</td></tr></table>";

$downloadFileName = 'test_report_'.time().'.xls';
 $filename = SITE_PATH_SPDATA."xml_data/reports/$downloadFileName";
 header("Cache-Control: no-store, no-cache, must-revalidate");
 header("Cache-Control: post-check=0, pre-check=0", false);
 header("Pragma: no-cache");
 header("Content-Type: application/vnd.ms-excel");
 header("Content-Length: strlen($achDowloadContent)");
 header("Content-Disposition:; filename=$downloadFileName");
 echo $contents;

?>