PHP数据导出Excel
来源:互联网 发布:孙骁骁人品知乎 编辑:程序博客网 时间:2024/06/16 06:11
需要将php数据导出Exel表格中,可以用PHPExcel,但是也有更快的方法,但是会出现些小问题
比如:
/* *处理Excel导出 *@param $datas array 设置表格数据 *@param $titlename string 设置head *@param $title string 设置表头 */ /*** */function excelData($datas,$titlename,$title,$filename){ $str = "<html xmlns:o=\"urn:schemas-microsoft-com:office:office\"\r\nxmlns:x=\"urn:schemas-microsoft-com:office:excel\"\r\nxmlns=\"http://www.w3.org/TR/REC-html40\">\r\n<head>\r\n<meta http-equiv=Content-Type content=\"text/html; charset=utf-8\">\r\n</head>\r\n<body>"; $str .= $title; $str .="<table border=1><head>".$titlename."</head>"; foreach ($datas as $key=> $rt ) { $str .= "<tr>"; foreach ( $rt as $k => $v ) { $str .= "<td>{$v}</td>"; } $str .= "</tr>\n"; } $str .= "</table></body></html>"; header( "Content-Type: application/vnd.ms-excel; name='excel'" ); header( "Content-type: application/octet-stream" ); header( "Content-Disposition: attachment; filename=".$filename ); header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" ); header( "Pragma: no-cache" ); header( "Expires: 0" ); exit( $str ); }
实例:
$dataResult=[[1,2,3,4,5,6]]; //导出数据$headTitle = "测试excel项目记录"; $title = "测试excel"; $headtitle= "<tr style='height:50px;border-style:none;'><th border=\"0\" style='height:60px;width:270px;font-size:22px;' colspan='11' >{$headTitle}</th></tr>"; $titlename = "<tr> <th style='width:70px;' >项目1</th> <th style='width:70px;' >项目2</th> <th style='width:70px;'>项目3</th> <th style='width:150px;'>项目4</th> <th style='width:70px;'>项目5</th> <th style='width:70px;'>项目6</th> </tr>"; $filename = $title.".xls"; excelData($dataResult,$titlename,$headtitle,$filename);
实践可以使用,自己封装
阅读全文
0 0
- php导出excel数据
- php导出excel数据
- php导出数据excel
- PHP数据导出Excel
- php 导出数据到 Excel
- php mysql数据导出excel
- php导出excel格式数据
- PHP导出 Excel表格数据
- PHP导出数据到Excel
- php、mysql导出excel数据
- php 导出数据到excel
- PHP导出MySQL数据到Excel文件
- PHP导出MySQL数据到Excel文件
- PHP导出MySQL数据到Excel文件
- PHP导出MySQL数据到Excel文件
- PHP导出MySQL数据到Excel文件
- php导出Mysql数据到Excel
- PHP导出MySQL数据到Excel文件
- English--从头开始
- 基于dubbo从传统MVC架构转向SOA架构分布式设计1--(helloword)
- Linux学习日志 2017/11/16
- openfire的MUC改造类似QQ永久群
- MySQL函数 split
- PHP数据导出Excel
- cookies工具类
- Spring和Struts2的整合
- 升级PHP7遇到的问题
- 各种流行的编程风格,你属于哪一种?
- 大型网站的灵魂——性能
- 链表问题---两个单链表相交的一系列问题
- mark: jstack、jmap和jstat命令
- 字符串转整形、ComBoBox用法