首页 > PHP
超简单的导出Excel数据
来源:TP课堂 时间:2020-12-02 点击:734

想导出Excel数据?

是不是有人告诉过你下载这个,引入那个。来个超简单的。

 $innerdata = Db::name('order')->select();
        $table = '';
        $table .= "<table>
            <thead>
                <tr>
                    <th class='name'>名称</th>
                    <th class='name'>入库日期</th>
                    <th class='name'>入库库位</th>
                    <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['out_trade_no']}</td>
                    <td class='name'>{$v['time']}</td>
                    <td class='name'>{$v['shou_name']}</td>
                    <td class='name'>{$v['total_price']}</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;