setHeader($excel_file_name); require_once "$php_page"; } function setHeader($excel_file_name)//this function used to set the header variable { header("Content-type: text/csv"); header("Content-type: application/octet-stream");//A MIME attachment with the content type "application/octet-stream" is a binary file. header("Content-type: application/x-msdownload"); header('Content-Type: application/vnd.ms-excel; charset=UTF-8'); header("Content-type: application/x-msdownload"); //Typically, it will be an application or a document that must be opened in an application, such as a spreadsheet or word processor. header("Content-Disposition: attachment; filename=$excel_file_name");//with this extension of file name you tell what kind of file it is. header("Pragma: no-cache");//Prevent Caching header("Expires: 0");//Expires and 0 mean that the browser will not cache the page on your hard drive } function exportWithQuery($qry,$excel_file_name,$conn)//to export with query { $tmprst = $db->query($qry,$conn); $header="
| Personal Details | "; $num_field=mysqli_num_fields($tmprst); foreach($tmprst,MYSQL_BOTH->fetchAll() as $row) { $body.="
|---|
| ".$row[$i]." | "; } $body.="