导出数据到表格
public function excel(){
$filename = ‘导出表格‘;
$header = [‘编号‘,‘名称‘];
$index = [‘id‘,‘name‘];
$list = array(
0 => array(‘id‘ => 1, ‘name‘ => ‘fdfs‘),
1 => array(‘id‘ => 2, ‘name‘ => ‘ffdfdsafs‘),
2 => array(‘id‘ => 3, ‘name‘ => ‘fdfgdgsddfafass‘),
);
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=".$filename.".xls");
$table_header = rtrim(implode("\t",$header), "\t");
$strexport = $table_header."\r";
foreach ($list as $row){
foreach($index as $val){
$strexport .= $row[$val] . "\t";
}
rtrim($strexport,"\t");
$strexport .= "\r";
}
$strexport=iconv(‘UTF-8‘,"GB2312//IGNORE", $strexport);
exit($strexport);
}
原文地址:https://www.cnblogs.com/qixidi/p/10202476.html
时间: 2024-10-14 01:27:15