简单的php导出excel
2017-04-12 12:29
579 查看
PHPExcel类挺强大的,但是性能有些慢,简单的导出没有必要了,写一个简单导出excel。
还可以采用phpmyadmin 方法
ob_end_clean(); header("Content-type:application/octet-stream"); header("Accept-Ranges:bytes"); header("Content-type:application/vnd.ms-excel"); header("Content-Disposition:attachment;filename=fee_search_".date("Y-m-d").".xls"); header("Pragma: no-cache"); header("Expires: 0"); $date_strat = strtotime($_REQUEST['listen_time']); $date_end = $date_strat+86400; if($date_strat!=''){ $str = "AND lws_createtime Between ".$date_strat." AND ".$date_end.""; }else{ $str = ""; } $state = $_REQUEST['state']; $stutype = $_REQUEST['stutype']; if($state==''){ $state = 0; } if($stutype!=''&&$stutype!='undefined'){ $stu = " and lws_stutype='$stutype'"; } //导出xls 开始 $tag1=iconv("UTF-8", "GB2312", '姓名'); $tag2=iconv("UTF-8", "GB2312", '英文名'); $tag3=iconv("UTF-8", "GB2312", '邮箱'); $tag4=iconv("UTF-8", "GB2312", '手机'); $tag8=iconv("UTF-8", "GB2312", '手机归属地'); $tag5=iconv("UTF-8", "GB2312", '注册时间'); $tag6=iconv("UTF-8", "GB2312", '来源'); $tag7=iconv("UTF-8", "GB2312", '状态'); echo "<table border='1' cellspacing='0' cellpadding='0'>"; echo "<tr bgcolor='#ccc'>"; echo "<td width='100' align='center'>$tag1</td>"; e b431 cho "<td width='100' align='center'>$tag2</td>"; echo "<td width='200' align='center'>$tag3</td>"; echo "<td width='150' align='center'>$tag4</td>"; echo "<td width='100' align='center'>$tag8</td>"; echo "<td width='200' align='center'>$tag5</td>"; echo "<td width='150' align='center'>$tag6</td>"; echo "<td width='100' align='center'>$tag7</td>"; echo "</tr>"; $fix = C ('DB_PREFIX'); $student = M("student"); $find = $student->field("stu.lws_id,lws_nameen,SiteName,lws_area,lws_contactdate, lws_contacttime,lws_namecn,lws_email,lws_phone,lws_status,lws_createtime AS needtime,sc.lsc_id")->join("AS stu LEFT JOIN sitesource AS ss ON ss.ID = stu.lws_origin LEFT JOIN ".$fix."studentcontact AS sc ON sc.lws_id=stu.lws_id")->where("lws_status = $state AND lws_belong = 0 AND lws_advisorid = '".$_SESSION['arr']['uid']."' $str $stu GROUP BY stu.lws_id")->findall(); for($i=0;$i<count($find);$i++){ $namecn = iconv("UTF-8", "GB2312", $find[$i]['lws_namecn']); $nameen = iconv("UTF-8", "GB2312", $find[$i]['lws_nameen']); $email = iconv("UTF-8", "GB2312", $find[$i]['lws_email']); $phone = iconv("UTF-8", "GB2312", $find[$i]['lws_phone']); $area = iconv("UTF-8", "GB2312", $find[$i]['lws_area']); $netime = iconv("UTF-8", "GB2312", date("y-m-d H:i",$find[$i]['needtime'])); $site = iconv("UTF-8", "GB2312", $find[$i]['SiteName']); if($find[$i]['lsc_id']!=''){ if($stutype!=''){ $tact = iconv("UTF-8", "GB2312", '有效待联系'); }else{ $tact = iconv("UTF-8", "GB2312", '联络沟通问题'); } }else{ $tact = iconv("UTF-8", "GB2312", '新量'); } echo "<tr>"; echo "<td width='100' align='center'>$namecn</td>"; echo "<td width='100' align='center'>$nameen</td>"; echo "<td width='200' align='center'>$email</td>"; echo "<td width='150' align='center'>$phone</td>"; echo "<td width='100' align='center'>$area</td>"; echo "<td width='200' align='center'>$netime</td>"; echo "<td width='150' align='center'>$tact</td>"; echo "<td width='100' align='center'>$site</td>"; echo "</tr>"; }
还可以采用phpmyadmin 方法
<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-type" content="text/html;charset=UTF-8" /> <style id="Classeur1_16681_Styles"></style> </head> <body> <div id="Classeur1_16681" align=center x:publishsource="Excel"> <table x:str border=0 cellpadding=0 cellspacing=0 width=100% style="border-collapse: collapse"> <tr><td class=xl2216681 nowrap>1234</td><td class=xl2216681 nowrap>Robbin会吐口水</td></tr> <tr><td class=xl2216681 nowrap>5678</td><td class=xl2216681 nowrap>javaeye网站</td></tr> </table> </div> </body> </html>这下可以直接echo了,又不需要iconv转码,只要设置好HTML里的Content-type(这里用的是UTF-8),是不是有舒服的感觉呢? 当然header还是要加上
header("Content-type:application/vnd.ms-excel"); header("Content-Disposition:attachment;filename=export_data.xls");
相关文章推荐
- php自动导出excel的简单方法
- php简单导出excel
- php不使用插件导出excel的简单方法
- php把数据表导出为Excel表的最简单、最快的方法(不用插件)
- php把数据表导出为Excel表的最简单、最快的方法(不用插件)
- header()实现PHP最简单的导出excel,不需要引入操作excel类库
- 简单PHP导出Excel
- php简单导出excel
- PHP导出Excel最简单的方法
- PHP导出Excel简单实例
- php导出excel最简单的办法,无需phpexcel
- phpexcel 简单导出多个sheet
- php 简单导出excel功能
- php导出Excel文件简单的方法(非PHPEXCEL)
- phpexcel php导入导出excel表格的简单方法
- PHP导出excel(*.xls)文件的简单方法
- php不使用插件导出excel的简单方法
- PHP导出MySQL数据库为EXCEL文件格式(.xls)的方法 http://www.kankanblog.com/read.php/144.htm
- 简单、完美的导出excel/word报表解决方案
- 一键导出Word和Excel文件的简单服务器控件