当前位置:网站首页>PHP export excel table
PHP export excel table
2022-04-23 03:56:00 【Bug】
php preservation excel form
One , The first condition
Need to download phpExcel library Put it into your own web page code , Calling function require_once(“phpExcel_path”)
You can edit the to be exported excel Format the table .
Two , Introduce objects
$excel = new PHPExcel();
// establish Excel Input object
$write = new PHPExcel_Writer_Excel5($excel);
one , Create header
Define an array
$letter= array(‘A’,‘B’,‘C’,‘D’…);
Or numbers
Define header array :
$tableheader = array(‘ chinese ’,‘ chinese ’,‘ chinese ’,‘ chinese ’);
1, Write header
for($i = 0;$i < count($tableheader);$i++)
{
$excel->getActiveSheet()->setCellValue("$letter[$i]1","$tableheader[$i]");
}
Ii. , Record table data
Define the table body array :
$tablebody = array(‘ data ’,‘ data ’,‘ data ’,‘ data ’,‘ data ’);
$number The variable is the line sequence number , Change according to the demand .
for($i = 0;$i < count($tablebody);$i++)
{
$excel->getActiveSheet()->setCellValue("$letter[$i]$number","$tablebody[$i]");
}
3、 ... and , preservation
The basic data is recorded
Finally, save to local
header("Pragma: public");
header("Expires: 0");
ob_end_clean();
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
//header('Cache-Control: max-age=0');
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");
header("Content-Disposition:attachment;filename=$project_code.$datetmp.xls");
header("Content-Transfer-Encoding:binary");
$write->save('php://output')
Four , Format table
The basic form is saved as mentioned above , You need to save a table with a certain format, and you need to set the cells .
one , establish sheet surface
$i Variables are equivalent to representing sheet Tabular id Number ,
$sheet_name The variable is the name of the table , It can also be set without , There is a default name .
$excel->createSheet(); // establish sheet
$excel->setactivesheetindex($i); //sheet Indexes
$excel->getActiveSheet()->setTitle($sheet_name);
Ii. , Cell settings
1, merge cell
2, Cell background color
3, font size
4, The font color
5, Font background color
6, Font settings
7, Cell width and height
Set up B The column width is 10
$excel->getActiveSheet()->getColumnDimension()->setAutoSize(true);
$excel->getActiveSheet()->getColumnDimension(\'B\')->setWidth(10);
版权声明
本文为[Bug]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230351311534.html
边栏推荐
- Retrieval question answering system baseline
- ROS series (I): rapid installation of ROS
- Variables, constants, operators
- Qt程序集成EasyPlayer-RTSP流媒体播放器出现画面闪烁是什么原因?
- Installation and configuration of clion under win10
- MySQL zip installation tutorial
- What if win10 doesn't have a local group policy?
- 【ICCV 2019】MAP-VAE:Multi-Angle Point Cloud-VAE: Unsupervised Feature Learning for 3D Point Clouds..
- Basic introduction to spot gold
- Shopping mall for transportation tools based on PHP
猜你喜欢
What if you encounter symbols you don't know in mathematical formulas
Install PaddlePaddle on ARM
Machine translation baseline
Basic knowledge of convolutional neural network
Wechat applet canvas draws a simple asymptotic color of the dashboard
Paddlepaddle does not support arm64 architecture.
作为一名码农,女友比自己更能码是一种什么体验?
Now is the best time to empower industrial visual inspection with AI
Xshell、Xftp连接新创建的Unbutu系统虚拟机全流程
创下国产手机在海外市场销量最高纪录的小米,重新关注国内市场
随机推荐
As a code farmer, what kind of experience is it that a girlfriend can code better than herself?
Nel ASA:挪威Herøya设施正式启用
ROS series (III): introduction to ROS architecture
Numpy's broadcasting mechanism (with examples)
Install PaddlePaddle on ARM
Express中间件②(中间件的分类)
php导出Excel表格
Vscode download and installation + running C language
QtSpim手册-中文翻译
The great gods in acmer like mathematics very much
QT program integration easyplayer RTSP streaming media player screen flicker what is the reason?
CRF based medical entity recognition baseline
Basic knowledge of convolutional neural network
PolarMask is not in the models registry
SQL topic exercise summary
[latex] differences in the way scores are written
Jupiter notebook modify configuration file setting startup directory is invalid
【ICCV 2019】MAP-VAE:Multi-Angle Point Cloud-VAE: Unsupervised Feature Learning for 3D Point Clouds..
硬核拆芯片
Raspberry pie 3B logs into the wired end of Ruijie campus network through mentohust, creates WiFi (open hotspot) for other devices, and realizes self startup at the same time