PHP导出Excel最简单的方法

        $rtn = $this->reply->getReply();
        if(isset($rtn) && count($rtn) > 0){
            header("Content-type:application/octet-stream");
            header("Accept-Ranges:bytes");
            header("Content-type:application/vnd.ms-excel");  
            header("Content-Disposition:attachment;filename=用户意见.xls");
            header("Pragma: no-cache");
            header("Expires: 0");

            $rtnCount = count($rtn);
            $data = array();
            $data[] = iconv("utf-8","gbk","用户名\t意见\n");
            for($i=0;$i<$rtnCount;$i++){
                $data[] = iconv("utf-8","gbk",$rtn[$i]['username']."\t".$rtn[$i]['reply']."\n");
            }
            echo implode($data);
        }

你可能感兴趣的:(LAMP)