当前位置:网站首页>PHP export data as excel table
PHP export data as excel table
2022-06-24 15:23:00 【Action】
Go straight to the code :
<?php
/**
* Export data as excel form
*@param $data A two-dimensional array , The structure is like an array from a database
*@param $title excel The first line of the title , An array , If it is empty, there is no title
*@param $filename Download file name
*/
function exportExcel($data=array(),$title=array(),$filename='test'){
header("Content-type:application/octet-stream");
header("Accept-Ranges:bytes");
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=".$filename.".xlsx");
header("Pragma: no-cache");
header("Expires: 0");
// export xls Start
if (!empty($title)){
foreach ($title as $k => $v) {
$title[$k]=iconv("UTF-8", "GB2312", $v);
}
$title= implode("\t", $title);
echo "$title\n";
}
if (!empty($data)){
foreach($data as $key=>$val){
foreach ($val as $ck => $cv) {
$data[$key][$ck]=iconv("UTF-8", "GB2312", $cv);
}
$data[$key]=implode("\t", $data[$key]);
}
echo implode("\n",$data);
}
}
$data = [
[' Zhang San ', 28, ' male '],
[' Li Si ', 18, ' Woman ']
];
$data = [
[
'name' => ' Zhang San ',
'age' => 28,
'sex' => ' male '
],
[
'name' => ' Li Si ',
'age' => 24,
'sex' => ' Woman '
],
];
$title = [' full name ', ' Gender ', ' Age '];
exportExcel($data, $title);The exported data is as follows :
边栏推荐
- Restoring to an earlier version in CVS
- 个人如何开户炒股 炒股开户安全吗
- As a developer, what is the most influential book for you?
- leetcode. 12 --- integer to Roman numeral
- CVPR2022 | 可精简域适应
- 安装wireshark时npcap怎么都安装不成功,建议先用winpcap
- A simple and powerful developer toolkit box3 cc
- Xingxinghai, it is said that the new generation can fight better?
- Esp32 series -- comparison of esp32 series
- Py's toad: a detailed introduction to toad, its installation and use
猜你喜欢

leetcode. 12 --- integer to Roman numeral

Two way combination of business and technology to build a bank data security management system

Left hand code, right hand open source, part of the open source road

Brief discussion on the implementation framework of enterprise power Bi CI /cd

Linux Installation cenos7 MySQL - 8.0.26

从pair到unordered_map,理论+leetcode题目实战
![[bitbear story collection] June MVP hero story | technology practice collision realm thinking](/img/b7/ca2f8cfb124e7c68da0293624911d1.png)
[bitbear story collection] June MVP hero story | technology practice collision realm thinking

List of PostgreSQL

Application of motion capture system in positioning and mapping of mobile robot in underground tunnel

常见的缺陷管理工具——禅道,从安装到使用手把手教会你
随机推荐
入行 4 年,跳槽 2 次,我摸透了软件测试这一行
A full set of tutorials for interviewers from Android manufacturers teach you: prepare for the interview and get the offer smoothly!
Huangchuping presided over the video conference on fixed-point contact with Zhuhai, resolutely implemented the deployment requirements of the provincial Party committee, and ensured positive results i
Teach you how to deploy the pressure test engine on Tencent cloud
Design of vga/lcd display controller system based on FPGA (Part 2)
Stm32f1 and stm32cubeide programming examples -ws2812b full color LED driver (based on spi+dma)
Is it safe to open an account in flush? What preparation is needed
【Kubernetes】1
Domestic payment system and payment background construction
Es search content top
Use tuples
update+catroot+c000021a+critical service failed+drivers+intelide+viaide+000000f
Monitoring and warning | is the website attacked?
常见的缺陷管理工具——禅道,从安装到使用手把手教会你
Go language concurrency model mpg model
Cvpr2022 | domaine compact adaptable
R language constructs regression model diagnosis (normality is invalid), performs variable transformation, and uses powertransform function in car package to perform box Cox transform to normality on
Port conflict handling method for tongweb
个人如何开户炒股 炒股开户安全吗
A brief introduction to the lexical analysis of PostgreSQL