phpexcel导出, 在本地正常,在服务器乱码
如题,在服务器运行时....
重复一下,在本地运行是正常的,放上服务就成这样了,代码如下。。。
$excel=new \phpexcel();
do{
$url='http://www.哪个好人来答下.com';
$content='';
$content=file_get_contents($url);
if($content['status']==0){
$data=$content['results'];
$head=array();
//获取表头值
for($i=0;$i$val){
for($i=0;$igetactivesheet()->setcellvalue($col[$i].$i,$row[$head[$i]]);
}
}
}
$page++;
}while($pagecount>=$page);
$excel->getactivesheet()->settitle($title);
$excel->setactivesheetindex(0);
$writer = \phpexcel_iofactory::createwriter($excel, 'excel5');
header('content-type: application/vnd.ms-excel');
header('content-disposition: attachment;filename='.$filename.'.xls');
header('cache-control: max-age=0');
$writer->save('php://output');
}
------解决思路----------------------
打开任何一个 xls 文件都会看到那个文件标识是顶格的,但你的截图中不是这样
请检查是否有 bom 头或其他输出
另外,那些 后边跟有空心方块的英文单词也是不应该有的,请检查相关的程序文件是否上传齐全了
------解决思路----------------------
header之前先清除缓存区的内容
ob_end_clean();// 就是加这句
header('content-type: application/vnd.ms-excel');
header('content-disposition: attachment;filename='.$filename.'.xls');
header('cache-control: max-age=0');