当前位置:网站首页>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
边栏推荐
- ROS series (IV): ROS communication mechanism series (5): Service Communication Practice
- 【NeurIPS 2019】Self-Supervised Deep Learning on Point Clouds by Reconstructing Space
- mui. Plusready does not take effect
- 【BIM入门实战】Revit建筑墙体:构造、包络、叠层图文详解
- Software testing process
- VS Studio 修改C语言scanf等报错
- ROS series (IV): ROS communication mechanism series (2): Service Communication
- Vs studio modifies C language scanf and other errors
- Mysql出现2013 Lost connection to MySQL server during query
- Writing latex with vscode - the latest tutorial 2022 / 4 / 17
猜你喜欢
Does China Mobile earn 285 million a day? In fact, 5g is difficult to bring more profits, so where is the money?
OpenCV----YOLACT实例分割模型推理
Who will answer the question?
VSCode配置之Matlab极简配置
MySQL zip installation tutorial
Express middleware ① (use of Middleware)
Xiaomi, which has set the highest sales record of domestic mobile phones in overseas markets, paid renewed attention to the domestic market
[latex] differences in the way scores are written
Solve the technical problems in seq2seq + attention machine translation
標識符、關鍵字、數據類型
随机推荐
Vscode download and installation + running C language
Using VBA interval to extract one column from another in Excel
SQL topic exercise summary
Basic introduction to spot gold
Identifier, keyword, data type
AI CC 2019 installation tutorial under win10 (super detailed - small white version)
Operating skills of spot gold_ Wave estimation curve
Nel ASA: her ø Ya facility in Norway officially opened
Wechat payment iframe sub page has no response
The whole process of connecting the newly created unbutu system virtual machine with xshell and xftp
对象和类的概念
Xshell、Xftp连接新创建的Unbutu系统虚拟机全流程
Activity supports multi window display
Common auxiliary classes
Identificateur, mot - clé, type de données
php导出Excel表格
[AI vision · quick review of NLP natural language processing papers today, issue 30] Thu, 14 APR 2022
单极性非归零NRZ码、双极性非归零NRZ码、2ASK、2FSK、2PSK、2DPSK及MATLAB仿真
Software testing process
[string] ranking of country names ----- problem solving notes