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

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";
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值