当前位置:网站首页>Two methods of generating excel table with PHP
Two methods of generating excel table with PHP
2022-07-27 16:24:00 【Collect and learn by yourself】
$html = data ;
1. ordinary excel surface , Cannot set style , Fast
$filename = ' Table name '.date('YmdHis');
$header = array('a','b','c','d');// Header
$index = array('key1','key2','key3','key4');// key
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=".$filename.".xls");// Different from the second method
$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);// Different from the second method
exit($strexport);// Different from the second method
2. In tabular form
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachement;filename=avvaa".date("Ymd").".xls");// Different from the first method
$html = '';
$html .= "<table><tr>";
// Export header ( That is, the fields in the table )
$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");;// Different from the first method
echo $html;;// Different from the first method
summary : There is a difference between the header and the following output , The first form cannot be generated excle surface
边栏推荐
猜你喜欢

Content ambiguity occurs when using transform:translate()

使用transform:translate()出现内容模糊问题

Nacos

Servlet basic knowledge points

Scratch crawler framework

mysql设置密码时报错 Your password does not satisfy the current policy requirements(修改·mysql密码策略设置简单密码)

Excel提取重复项

第21回---第30回

Keil implements compilation with makefile

Openwrt adds RTC (mcp7940 I2C bus) drive details
随机推荐
MapReduce instance (II): Average
C language programming (Third Edition)
JSP基础
Axure install Icon Font Catalog
Find active SQL connections in SQL Server
The difference and use between get request and post request
Chat skills
centos上mysql5.7主从热备设置
ARIMA模型选择与残差
Leetcode25 question: turn the linked list in a group of K -- detailed explanation of the difficult questions of the linked list
Sudden! 28 Chinese entities including Hikvision / Dahua / Shangtang / Kuangshi / ITU / iFLYTEK have been blacklisted by the United States
The first week of C language learning - the history of C language
Coturn service installation in webrtc
Determine the exact type of data
C language realizes the conversion between byte stream and hexadecimal string
Use of arrow function
ARIMA model selection and residuals
Addition of large numbers
Baidu picture copy picture address
指针总结