继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

PHP不使用phpexcel导出

lifeng_881888
关注TA
已关注
手记 45
粉丝 42
获赞 356

当前方式不能支持合并单元格等高级操作,只支持最简单的

    $filename = ’excel名称‘;
    $title = array('column_name1,column_name2,column_name3');
    $data = array(
        array(111,222,333),
        array(444,555,666),
        array(777,888,999),
    )
    $filename=iconv("UTF-8", "GB2312",$filename);
    header("Content-type:application/octet-stream");
    header("Accept-Ranges:bytes");
    header("Content-type:application/vnd.ms-excel");  
    header("Content-Disposition:attachment;filename=".$filename.".xls");
    header("Pragma: no-cache");
    header("Expires: 0");
    //导出xls 开始
    if (!empty($title)){
        foreach ($title as $k => $v) {
            $title[$k]=iconv("UTF-8", "GB2312",$v);
        }
        $title= implode("\t", $title);
        echo "$title\n";
    }
    if (!empty($data)){
        foreach($data as $key=>$val){
            foreach ($val as $ck => $cv) {
                $data[$key][$ck]=iconv("UTF-8", "GB2312", $cv);
            }
            $data[$key]=implode("\t", $data[$key]);
        }
        echo implode("\n",$data);
    }
打开App,阅读手记
1人推荐
发表评论
随时随地看视频慕课网APP