时间:2021-07-01 10:21:17 帮助过:38人阅读
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' => '公司'], ]);}