phpexcel导出文件后,wps能用 excel打开乱码解决
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了phpexcel导出文件后,wps能用 excel打开乱码解决相关的知识,希望对你有一定的参考价值。
导出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‘); }