执行导出的方法:
public function createtables($list, $filename, $header=array(), $index = array()) { header("Content-type:application/vnd.ms-excel"); header("Content-Disposition:filename=".$filename.".xls"); $teble_header = implode("\t",$header); $strexport = $teble_header."\r"; foreach ($list as $row){ foreach ($index as $val) { $strexport .= $row[$val]."\t"; } $strexport .= "\r"; } exit($strexport); }
调用方法:
$list=PointsErrors::find()->where(['batchSn' => $batchSn])->all();
$filename='错误报告-'.$batchSn.date('YmdHis');
$header = array('错误', '状态(1.未发送;2.发送成功)', '手机号', '身份证号', '是线上用户', '待发积分'); $index = array('errors', 'status', 'mobile', 'idCard', 'isOnline', 'points'); $this->createtable($list, $filename, $header, $index);