phpStudy6——php导出可以设置样式的excel表格
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了phpStudy6——php导出可以设置样式的excel表格,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2211字,纯文字阅读大概需要4分钟。
内容图文
![phpStudy6——php导出可以设置样式的excel表格](/upload/InfoBanner/zyjiaocheng/1112/ac1c0bad7c64423db8a8c54eba1bdacb.jpg)
前言:
一般的后台管理页面肯定少不了excel表格导出的功劳,尤其是那些电商平台的订单导入导出,用户列表的导入导出等,那么本文就介绍php是如何导出excel表格的。
php导出excel方法有很多,网上介绍比较多的是php默认的设置header的方法,以及使用phpexcel库。本文以php默认的方法为例进行演示,有感兴趣的可以去了解下phpexcel库的使用。
示例代码:
输出静态内容的表格:
1 <style> 2/*设置表格样式*/ 3table { 4 border-top: 1px solid #2af; 5 border-left: 1px solid #2af; 6} 7 .title{ 8 background:#2af; 9 color:#FFFFFF;10 font-weight:bold; 11} 12td { 13 text-align: center; 14 font-size: 12px; 15 font-family: Arial, Helvetica, sans-serif; 16 color: #152122;17} 18 td, th { 19 padding: 5px; 20 border: 0.05em solid #2af;21 border-left: 0; 22 border-top: 0; 23} 24 </style> 25 <?php 26//设置当前内容类型为excel表格,并设置文件扩展名为xls27header ( "Content-type:application/vnd.ms-excel" ); 28header ( "Content-Disposition:filename=csat.xls" ); 2930//输出表格31echo "<table width=‘800‘ border=‘0‘ cellspacing=‘0‘ cellspadding=‘0‘> 32 <tr> 33 <th class=‘title‘>编号</th> 34 <th class=‘title‘>姓名</th> 35 <th class=‘title‘>手机号码</th> 36 </tr> 37 <tr> 38 <td>1001</td> 39 <td>张三</td> 40 <td>13598759865</td> 41 </tr> 42 <tr> 43 <td>1002</td> 44 <td>李四</td> 45 <td>15698789658</td> 46 </tr> 47 </table>"; 48 ?>
实例解析:
关键代码:
1 // 输出表格页面的头部及样式 2 header ( "Content-type:application/vnd.ms-excel" ); 3header ( "Content-Disposition:filename=csat.xls" );
其实这个和前边输出html内容的设置类似
1header("Content-Type:text/html;charset=utf8");
将数据库查询的数据导出到excel表格:
关键代码:
1 // 输出每行数据 2 while($row =mysql_fetch_array($result)) { 3$userScore=(int)$row["userScore"]; 4$scoreLevel=""; 5if($userScore<60) $scoreLevel="三等奖"; 6if($userScore<100&&$userScore>=60) $scoreLevel="二等奖"; 7if($userScore>=100) $scoreLevel="一等奖"; 8 9echo ‘ <tr><td>‘; 10echo$row["userId"]; 11echo‘</td><td>‘; 12echo$row["userName"]; 13echo‘</td><td>‘; 14echo$row["phoneNumber"]; 15echo‘</td><td>‘; 16echo$row["userScore"]; 17echo‘</td><td>‘; 18echo$scoreLevel; 19echo‘</td><td>‘; 20echo$row["dataTime"]; 21echo ‘</td></tr>‘; 22 }
原文:http://www.cnblogs.com/xyyt/p/5650379.html
内容总结
以上是互联网集市为您收集整理的phpStudy6——php导出可以设置样式的excel表格全部内容,希望文章能够帮你解决phpStudy6——php导出可以设置样式的excel表格所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。