Heim  >  Artikel  >  Backend-Entwicklung  >  PHP excel导出乱码问题解决办法

PHP excel导出乱码问题解决办法

WBOY
WBOYOriginal
2016-06-23 13:18:501116Durchsuche

在2003及其它版本导出一切正常,但是在excel2007上导出乱码,处理方法:

string format for excel to export. Valid value are 'Excel5','Excel2007','Excel2003XML','00Calc','Gnumeric'.

找到createWrite方法,将第二个参数修改成需要生成的EXCEL版本型号:

如:

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');$objWriter->save('php://output');

当然了,如果用的是框架,如YII2框架,那么建议封装成一个小物件,推荐:

https://github.com/moonlandsoft/yii2-phpexcel

小物件使用方法:

use moonland\phpexcel\Excel;public function actionT(){    $result = Test::find()->all();    Excel::widget([        'models' => $result,        'mode' => 'export',        'format' => 'Excel5',        'columns' => ['itemid', 'username', 'company'],        'headers' => ['itemid' => 'ID号', 'username' => '用户名', 'company' => '公司'],    ]);}




Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn