PHP将操作数据库得到的数据生成Excel导出

来源:互联网 发布:极速开票软件 编辑:程序博客网 时间:2024/05/22 12:09
public function export()
    {
        Header( "Content-type:   application/octet-stream ");
        Header( "Accept-Ranges:   bytes ");
        Header( "Content-type:application/vnd.ms-excel ");   
        Header( "Content-Disposition:attachment;filename=ExportDate.xls ");
        $where="1=1";
        $date=$_POST["date_exp"];
        if($date=="今天")
        {
            $time1 = strtotime(date("Y-m-d",time()));
            $time2 = $time1 + 3600*24;
            $where = $where." and `inputtime` between '$time1' and '$time2' ";
        }
        else if($date=="昨天")
        {
            $time1 = strtotime(date("Y-m-d",time()));
            $time2 = $time1 - 3600*24;
            $where =$where. " and `inputtime` between '$time2' and '$time1' ";
        }
        else if($date=="上周")
        {
            $now = time();
            $date = $now - 7*24*60*60;
            $where=$where." and `inputtime` >= '$date' ";
        }
        else if($date=="最近30天")
        {
            $now = time();
            $date = $now - 30*24*60*60;
            $where=$where." and `inputtime` >= '$date' ";
        }

        $this->db->set_model(12);      //12对应于content模块对应的modelid
        $dates=$this->db->select($where,'*','','inputtime desc');
        echo "ID \t 栏目\t 姓名 \t详细地址 \t QQ \t Email \t 电话 \t 手机 \t 发布日期 \n";

        for ($i=0;$i<count($dates);$i++)
        {
            echo $dates[$i][id]."\t";
            echo $dates[$i][catid]."\t".$dates[$i][name]."\t".$dates[$i][address]."\t".$dates[$i][qq]."\t".$dates[$i][email]."\t".$dates[$i][telephone]."\t".$dates[$i][mobilephone]."\t".date("Y-m-d H:i",$dates[$i][inputtime])."\n";
        }
    }
0 0
原创粉丝点击