1. 程式人生 > >phpexcel導出文件後,wps能用 excel打開亂碼解決

phpexcel導出文件後,wps能用 excel打開亂碼解決

-type code post exe 導出文件 osi creat function new

導出excel後wps能用 excel打開亂碼,是因為導出的類使用方式問題

把$objWriter = new \PHPExcel_Writer_Excel2007($this->_obj);

換成$objWriter = \PHPExcel_IOFactory::createWriter($this->_obj, ‘Excel5‘); 就能解決問題

 public function output($file_name){
        //直接輸出到瀏覽器
        header("Pragma: public");
        header("Expires: 0");
        
header("Cache-Control:must-revalidate, post-check=0, pre-check=0"); header("Content-Type:application/force-download"); header("Content-Type:application/ms-execl"); header("Content-Type:application/octet-stream"); header("Content-Type:application/download"); header(‘Content-Disposition:attachment;filename="‘.$file_name
); header("Content-Transfer-Encoding:binary"); // $objWriter = new \PHPExcel_Writer_Excel2007($this->_obj); 直接使用會導致wps能用,excel打開報錯,產生亂碼 $objWriter = \PHPExcel_IOFactory::createWriter($this->_obj, ‘Excel5‘); //下面的用法就能解決 $objWriter->save(‘php://output‘); }

phpexcel導出文件後,wps能用 excel打開亂碼解決