php导出excel表格

来源:互联网 发布:淘宝联盟默认推广位 编辑:程序博客网 时间:2024/03/28 21:19

执行导出的方法:

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);

原创粉丝点击