Home >Backend Development >PHP Tutorial >phpExcel导出, 在本地正常,在服务器乱码解决办法
phpExcel导出, 在本地正常,在服务器乱码
如题,在服务器运行时....
重复一下,在本地运行是正常的,放上服务就成这样了,代码如下。。。
<br /> $excel=new \PHPExcel();<br /> do{<br /> $url='http://www.哪个好人来答下.com';<br /> <br /> $content='';<br /> $content=file_get_contents($url); <br /> if($content['status']==0){ <br /> $data=$content['results'];<br /> <br /> $head=array();<br /> <br /> //获取表头值<br /> for($i=0;$i<10;$i++){<br /> $tmp=array_keys($data[$i]);<br /> foreach($tmp as $t){<br /> if(!in_array($t,$head)){<br /> array_push($head,$t);<br /> }<br /> }<br /> }<br /> <br /> $A=65; //A的ASCII值<br /> $col=array();<br /> for($i=0;$i<count($head);$i++){ //制作列值<br /> array_push($col,chr($A++));<br /> }<br /> for($i=0;$i<count($head);$i++){ //制作表头<br /> $excel->getActiveSheet()->setCellValue($col[$i].'1',$head[$i]);<br /> }<br /> } <br /> foreach($data as $key=>$val){ <br /> for($i=0;$i<count($head);$i++){<br /><br /> $excel->getActiveSheet()->setCellValue($col[$i].$i,$row[$head[$i]]);<br /> <br /> }<br /> }<br /> <br /> }<br /> $page++;<br /> }while($pageCount>=$page);<br /> $excel->getActiveSheet()->setTitle($title);<br /> $excel->setActiveSheetIndex(0);<br /> <br /> $writer = \PHPExcel_IOFactory::createWriter($excel, 'Excel5');<br /> header('Content-Type: application/vnd.ms-excel');<br /> header('Content-Disposition: attachment;filename="'.$fileName.'.xls"');<br /> header('Cache-Control: max-age=0');<br /> <br /> $writer->save('php://output');<br /> <br /> }<br />
<br />ob_end_clean();// 就是加这句<br /><br />header('Content-Type: application/vnd.ms-excel');<br />header('Content-Disposition: attachment;filename="'.$fileName.'.xls"');<br />header('Cache-Control: max-age=0');<br />