PHP导出excel,不引入phpexcel类库,导出excel数据

精帖
收藏
3 2323
PHP技术
PHP技术 2017-08-02 16:22:49
付费话题:0 积分

php导出excel最简单的办法,无需phpexcel

public function  exportDayInner(){
    $innerdata = Db::name('user')
        ->field('username,mobile,email,create_time')
        ->select();
    $table = '';
    $table .= "<table>
    <thead>
        <tr>
            <th class='name'>用户名称</th>
            <th class='name'>用户手机号</th>
            <th class='name'>用户邮箱</th>
            <th class='name'>注册时间</th>
        </tr>
    </thead>
    <tbody>";
    foreach ($innerdata as $v) {
        $table .= "<tr>
            <td class='name'>{$v['username']}</td>
            <td class='name'>{$v['mobile']}</td>
            <td class='name'>{$v['email']}</td>
            <td class='name'>{$v['create_time']}</td>
        </tr>";
    }
    $table .= "</tbody></table>";
    //通过header头控制输出excel表格
    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/vnd.ms-execl");
    header("Content-Type:application/octet-stream");
    header("Content-Type:application/download");;
    header('Content-Disposition:attachment;filename="测试.xls"');
    header("Content-Transfer-Encoding:binary");
    echo $table;
}


评论话题
提交