php 方便快捷导出excel
/**
* 导出excel
* @param array $column
* eg: $column = [
* 'username' => '姓名',
* 'age' => '年龄',
* 'sex' => '性别'
* ]
* @param array $data
* eg: $data = [
* ['username' => 'yht', 'age'=>20, 'sex'=>'男'],
* ['username' => 'jsh', 'age'=>18, 'sex'=>'女'],
* ['username' => 'klerk', 'age'=>25, 'sex'=>'男'],
* ]
*/
public static function exportExcel($column, $data)
{
$keys = array_keys($column); header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=export_data.xls"); $html = '<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">';
$html .= ' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
$html .= ' <html> ';
$html .= ' <head> ';
$html .= ' <meta http-equiv="Content-type" content="text/html;charset=UTF-8" /> ';
$html .= ' <style id="Classeur1_16681_Styles"></style> ';
$html .= ' </head> ';
$html .= ' <body border=1> ';
$html .= ' <div id="Classeur1_16681" align=center x:publishsource="Excel"> ';
$html .= ' <table x:str border=1 cellpadding=1 cellspacing=1 width=100% style="border-collapse: collapse">';
$html .= ' <tr>';
foreach($column as $key => $value){
$html .= ' <td>' . Html::encode($value) . '</td>';
}
$html .= ' </tr>';
if($data) {
foreach ($data as $key => $value) {
$html .= ' <tr>';
foreach ($keys as $val){
$html .= ' <td>' . $value[$val] . '</td>';
}
$html .= ' </tr>';
}
}
$html .= ' </table> ';
$html .= ' </div> ';
$html .= ' </body> ';
$html .= ' </html> ';
echo $html;
}
php 方便快捷导出excel的更多相关文章
- JAVA原始的导出excel文件,快捷通用 方便 还能够导出word文档哦
如今导出excel基本上都是用poi了,当报表格式非常负责的时候 开发难度会加大 假设报表有格式有变化 那就更复杂了,先发现一个非常老的技术.能够解决格式复杂的报表. 实例代码例如以下: <%@ ...
- MyXls导出Excel的各种设置
MyXls是一个操作Excel的开源类库,支持设置字体.列宽.行高(由BOSSMA实现).合并单元格.边框.背景颜色.数据类型.自动换行.对齐方式等,通过众多项目的使用表现,证明MyXls对于创建简单 ...
- C#使用Aspose.Cells导出Excel简单实现
首先,需要添加引用Aspose.Cells.dll,官网下载地址:http://downloads.aspose.com/cells/net 将DataTable导出Xlsx格式的文件下载(网页输出) ...
- 利用poi导出Excel
import java.lang.reflect.Field;import java.lang.reflect.InvocationTargetException;import java.lang.r ...
- [django]数据导出excel升级强化版(很强大!)
不多说了,原理采用xlwt导出excel文件,所谓的强化版指的是实现在网页上选择一定条件导出对应的数据 之前我的博文出过这类文章,但只是实现导出数据,这次左思右想,再加上网上的搜索,终于找出方法实现条 ...
- NPOI导出Excel
using System;using System.Collections.Generic;using System.Linq;using System.Text;#region NPOIusing ...
- ASP.NET Core 导入导出Excel xlsx 文件
ASP.NET Core 使用EPPlus.Core导入导出Excel xlsx 文件,EPPlus.Core支持Excel 2007/2010 xlsx文件导入导出,可以运行在Windows, Li ...
- asp.net DataTable导出Excel 自定义列名
1.添加引用NPOI.dll 2.cs文件头部添加 using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using System.IO; 3.代码如 ...
- Aspose.Cells导出Excel(1)
利用Aspose.Cells导出excel 注意的问题 1.DataTable的处理 2.进行编码,便于中文名文件下载 3.别忘了Aspose.Cells.dll(可以自己在网上搜索) public ...
随机推荐
- 关于okhttp
本文出处:http://www.tuicool.com/articles/rArq63u 为什么需要一个HTTP库 Android系统提供了两种HTTP通信类,HttpURLConnection和Ht ...
- git flow的安装和使用
确保安装了git 1.windows系统下安装 进入cmd clone github上的gitflow到一个文件夹下 我这里clone到 c:\gitflow git clone git://gith ...
- (light OJ 1005) Rooks dp
http://www.lightoj.com/volume_showproblem.php?problem=1005 PDF (English) Statistics Forum Tim ...
- IIS Connection Timeout vs httpRuntime executionTimeout
IIS Connection Timeout specifies how long, in seconds, should the code wait before timing out from t ...
- 第37讲:List的foldLeft、foldRight、sort操作代码实战
其实flodLeft和foldRight就是折叠操作,我让们看下下列的函数 折叠操作 def sum(xs:List[Int]):Int = ( 0 /: xs)(_ +_) def p ...
- Visual Stuido 在文件中查找不显示结果
出现好几次了.解决方法如下: 注册表找到 HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{73B7DC00-F498-4ABD-AB79-D07AFD52F395}\InPr ...
- jsp连接sqlServer数据库教程
一.首先讲下我用的工具版本以供参考: jar包:jtds1.3.1.jar 下载地址:点击进入 数据库:SQL Server2012 服务器:Tomcat8.0 下载地址:点击进入 开发IDE工 ...
- MVC中使用RazorPDF创建PDF
这篇文章主要介绍使用Nuget package中的RazorPDF简单的创建PDF的方法. 关于RazorPDF 这个Nuget Package由Al Nyveldt创建.它内部使用ITextShar ...
- Chrome RenderText分析(2)
接Chrome RenderText分析(1) 继续分析以下步骤 一.TextRun结构 struct TextRun { TextRun(); ~TextRun(); ui::Range r ...
- [ACM_搜索] POJ 1096 Space Station Shielding (搜索 + 洪泛算法Flood_Fill)
Description Roger Wilco is in charge of the design of a low orbiting space station for the planet Ma ...