导出数据到表格PHP
Posted 栖息地
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了导出数据到表格PHP相关的知识,希望对你有一定的参考价值。
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(" ",$header), " ");
$strexport = $table_header."
";
foreach ($list as $row){
foreach($index as $val){
$strexport .= $row[$val] . " ";
}
rtrim($strexport," ");
$strexport .= "
";
}
$strexport=iconv(‘UTF-8‘,"GB2312//IGNORE", $strexport);
exit($strexport);
}
以上是关于导出数据到表格PHP的主要内容,如果未能解决你的问题,请参考以下文章