当前位置:网站首页>php 生成excel表的2种方法
php 生成excel表的2种方法
2022-07-15 16:49:00 【自己收藏学习】
$html = 数据;
1.简单的excel表,不能设置样式,速度快
$filename = '表名'.date('YmdHis');
$header = array('a','b','c','d');//表头
$index = array('key1','key2','key3','key4');//键
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=".$filename.".xls");//跟第二种方法有差异
$teble_header = implode("\t",$header);
$strexport = $teble_header."\r";
foreach ($html as $row){
foreach($index as $val){
$strexport.=$row[$val]."\t";
}
$strexport.="\r";
}
$strexport=iconv('UTF-8',"GB2312//IGNORE",$strexport);//跟第二种方法有差异
exit($strexport);//跟第二种方法有差异
2.用表格形式
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachement;filename=avvaa".date("Ymd").".xls");//跟第一处方法差异
$html = '';
$html .= "<table><tr>";
//导出表头(也就是表中拥有的字段)
$html .= "<th>1</th><th>2</th><th>3</th><th>4</th><th>5</th><th>6</th>";
$html .= "</tr>";
for($i=0;$i<4;$i++){
$html .= "<tr><td>a</td><td>b</td><td>c</td><td>d</td><td>e</td><td>f</td></tr>";
}
$html.= "</table>";
$html = mb_convert_encoding($html,"gb2312","utf-8");;//跟第一处方法差异
echo $html;;//跟第一处方法差异
总结:就是表头和后面输出的地方有差异,表格的用第一种生成不了excle表
边栏推荐
猜你喜欢
随机推荐
Serialization and deserialization of flip word /maxqueue/ quadratic tree
FFmpeg sample 分析:muxing.c
Ldr9201 audio digital decoding DAC plus ldr6023c digital plus PD fast charging scheme
room android sqlite
Explanation of smart factory terms
设置dropout参数技巧
compileflow 淘宝工作流引擎
Compileflow Taobao workflow engine
Excel import / export annotation General Edition
H264-解码顺序 显示顺序 参考顺序
Asymmetric encryption RSA and symmetric encryption AES project application
About some string related functions, memory functions and some simulations
markdown学习笔记 第二章 基本语法 (markdown编辑器下显示)
Explanation of specific terms of smart factory
完全讲清楚stats.t.interval的用法
关于一些字符串相关函数,内存函数及部分模拟
yolact模型结构探索
The IP address of the database is stored. What data type is used
联想电源管理下载
Reading notes: review of process consulting I II III









