php export excel
composer require phpoffice/phpspreadsheet
php export excel
composer require phpoffice/phpspreadsheet
header export excel data only php
1 /**
2 * Export data to excel
3 *@param $data A two-dimensional array, the structure of which is similar to the array found from the database
4 *@param $title excel The first row title of, an array, if empty, no title
5 *@param $filename Downloaded file name
6 *@examlpe10 */
11 function exportexcel($data=array(),$title=array(),$filename='report'){
12 ob_end_clean();
13 ob_start();
14 header("Content-type:application/octet-stream");
15 header("Accept-Ranges:bytes");
16 header("Content-type:application/vnd.ms-excel");
17 header("Content-Disposition:attachment;filename=".$filename.".xls");
18 header("Pragma: no-cache");
19 header("Expires: 0");
20 //export xls start
21 if (!empty($title)){
22 foreach ($title as $k => $v) {
23 $title[$k]=iconv("UTF-8", "GB2312",$v);
24 }
25 $title= implode("\t", $title);
26 echo "$title\n";
27 }
28 if (!empty($data)){
29 foreach($data as $key=>$val){
30 foreach ($val as $ck => $cv) {
31 $data[$key][$ck]=iconv("UTF-8", "GB2312", $cv);
32 }
33 $data[$key]=implode("\t", $data[$key]);
34 }
35 echo implode("\n",$data);
36 }
37 }
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us