亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

用php把數據導出excel

標簽:
PHP

一:先获取数据

<!--more-->

public function output($dataResult=array()){
    $headTitle = date('YmdHis');
    $title = date('YmdHis');
    $headtitle= "<tr style='height:50px;border-style:none;><th border=\"0\" style='height:60px;width:270px;font-size:22px;' colspan='11' >{$headTitle}</th></tr>";
    $titlename = '';
    $headtitle = "<tr>
           <th>ID</th>
           <th>条码号</th>
           <th>商品组合</th>
           <th>项目明细</th>
           <th>病人</th>
           <th>医生姓名</th>
           <th>医生折扣</th>
           <th>代理姓名</th>
           <th>业务员</th>
           <th>原价</th>
           <th>实付</th>
           <th>退款</th>
           <th>日期</th>
       </tr>";
    $filename = $title.".xls";
    $this->excelData($dataResult,$titlename,$headtitle,$filename);
}

二:输出

    /*
 *处理Excel导出
 *@param $datas array 设置表格数据
 *@param $titlename string 设置head
 *@param $title string 设置表头
 */
private function excelData($datas,$titlename,$title,$filename){
    $str = "<html xmlns:o=\"urn:schemas-microsoft-com:office:office\"\r\nxmlns:x=\"urn:schemas-microsoft-com:office:excel\"\r\nxmlns=\"http://www.w3.org/TR/REC-html40\">\r\n<head>\r\n<meta http-equiv=Content-Type content=\"text/html; charset=utf-8\">\r\n</head>\r\n<body>";
    $str .="<table border=1><head>".$titlename."</head>";
    $str .= $title;
    foreach ($datas  as $key=> $rt )
    {
        $str .= "<tr>";
        foreach ( $rt as $k => $v )
        {
            $str .= "<td>'{$v}</td>";
        }
        $str .= "</tr>\n";
    }
    $str .= "</table></body></html>";
    header("Content-type:application/vnd.ms-excel");
    //header( "Content-Type: application/vnd.ms-excel; name='excel'" );
    //header( "Content-type: application/octet-stream" );
    header( "Content-Disposition: attachment; filename=".$filename );
    //header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
    header( "Pragma: no-cache" );
    header( "Expires: 0" );
    exit( $str );
}
點擊查看更多內容
5人點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
PHP開發工程師
手記
粉絲
12
獲贊與收藏
161

關注作者,訂閱最新文章

閱讀免費教程

感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消