简单的php导出excel
来源:互联网 发布:上海淘宝代运营公司 编辑:程序博客网 时间:2024/06/06 04:50
PHPExcel类挺强大的,但是性能有些慢,简单的导出没有必要了,写一个简单导出excel。
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>";echo "<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");
0 0
- 简单的php导出excel
- php简单导出excel
- php简单导出excel
- 简单PHP导出Excel
- PHP导出EXCEL的简单函数
- PHP导出Excel最简单的方法
- PHP导出excel(*.xls)文件的简单方法
- phpexcel php导入导出excel表格的简单方法
- php导出Excel文件简单的方法(非PHPEXCEL)
- php导出excel最简单的办法,无需phpexcel
- php 导出excel 很简单很好用
- php导出excel表简单方式
- php实现excel的导出
- 最简单的Excel导出
- 简单的excel操作--导出
- 比较简单的导出EXCEL
- 简单的导出excel 表格
- 简单的实现excel导出
- Java-Eclipse使用maven搭建spring mvc
- cuda笔记
- java中一个子线程如何通过interrupt手段来停止主线程
- (LeetCode) 543. Diameter of Binary Tree
- 自低向上分析网络最小传输单元结构:以太网 + IP + TCP
- 简单的php导出excel
- Dice (简单广搜)
- 正则表达式部分替换
- 不忘初心
- 球对称广义调和形式
- Linux mount/unmount命令(转)
- Laravel regex验证的正确写法
- php闭包函数学习
- hibernate原生sql查询映射java bean问题,出现Ljava.lang.object错误