用phpexcel导出数据后,为什么excel打不开

2025-05-14 21:58:41
推荐回答(1个)
回答(1):

自己写吧 别用PHPExcel了

//$fileName文件名
//$headArr标题
//$data数据
public function getExcel($fileName,$headArr,$data){
header("Content-type:application/octet-stream");
header("Accept-Ranges:bytes");
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename={$fileName}.xls");
header("Pragma: no-cache");
header("Expires: 0");
array_unshift($data,$headArr);
foreach($data as $key => $val){
$data[$key]=implode("\t", $data[$key]);
}
echo iconv('utf-8','gbk',implode("\n",$data));
}

这是我自己写的 比较简单
如果需求没要求导出的excel要排版 设置样式之类的话
就凑合着用吧