导出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‘); }
时间: 2024-09-29 23:28:00