当前位置:网站首页>php导出Excel表格
php导出Excel表格
2022-04-23 03:51:00 【撸BUG】
php保存excel表格
一,首要条件
需要下载phpExcel库 放到自己网页代码目,在调用函数require_once(“phpExcel_path”)
即可对即将导出的excel表格进行格式设置。
二,引入对象
$excel = new PHPExcel();
//创建Excel输入对象
$write = new PHPExcel_Writer_Excel5($excel);
壹,创建表头
定义数组
$letter= array(‘A’,‘B’,‘C’,‘D’…);
或者是数字
定义表头数组:
$tableheader = array(‘中文’,‘中文’,‘中文’,‘中文’);
1,写入表头
for($i = 0;$i < count($tableheader);$i++)
{
$excel->getActiveSheet()->setCellValue("$letter[$i]1","$tableheader[$i]");
}
贰,记录表数据
定义表主体数组:
$tablebody = array(‘数据’,‘数据’,‘数据’,‘数据’,‘数据’);
$number变量是行序号 ,根据需求更改。
for($i = 0;$i < count($tablebody);$i++)
{
$excel->getActiveSheet()->setCellValue("$letter[$i]$number","$tablebody[$i]");
}
三,保存
记录数据就基本完成
最后就是保存到本地
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')
四,设置表格格式
基础表格保存就如上所诉,需要保存一定格式的表格需要对单元格进行设置。
壹,创建sheet表
$i变量相当于表示sheet表的id号,
$sheet_name变量是表的名字,也可以不用设置,有默认名。
$excel->createSheet(); //创建sheet
$excel->setactivesheetindex($i); //sheet索引
$excel->getActiveSheet()->setTitle($sheet_name);
贰,单元格设置
1,合并单元格
2,单元格背景色
3,字体大小
4,字体颜色
5,字体背景色
6,字体设置
7,单元格宽高
设置B列宽度为 10
$excel->getActiveSheet()->getColumnDimension()->setAutoSize(true);
$excel->getActiveSheet()->getColumnDimension(\'B\')->setWidth(10);
版权声明
本文为[撸BUG]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_45647036/article/details/124247645
边栏推荐
- Install PaddlePaddle on ARM
- Numpy's broadcasting mechanism (with examples)
- What if you encounter symbols you don't know in mathematical formulas
- Nel ASA:挪威Herøya设施正式启用
- Wechat applet canvas draws a simple asymptotic color of the dashboard
- Mechanical design knowledge point planning
- Who will answer the question?
- 现货黄金基本介绍
- ROS series (4): ROS communication mechanism series (4): topic communication practice
- MySQL zip installation tutorial
猜你喜欢
Variables, constants, operators
[AI vision · quick review of robot papers today, issue 29] Mon, 14 Feb 2022
ROS series (IV): ROS communication mechanism series (2): Service Communication
ROS series (I): rapid installation of ROS
MySQL is completely uninstalled and MySQL service is cleaned up
常用的辅助类
Solve the technical problems in seq2seq + attention machine translation
Openvino only supports Intel CPUs of generation 6 and above
Notes sur l'apprentissage profond (Ⅱ) - - Principe et mise en oeuvre de la fonction d'activation
Installation and configuration of clion under win10
随机推荐
Several common methods of multithreading
Xshell、Xftp连接新创建的Unbutu系统虚拟机全流程
If statement format flow
Identificateur, mot - clé, type de données
对象和类的概念
The super large image labels in remote sensing data set are cut into specified sizes and saved into coco data set - target detection
深度學習筆記(二)——激活函數原理與實現
硬核拆芯片
(valid for personal testing) compilation guide of paddedetection on Jetson
A hundred dollars for a hundred chickens
RuntimeError: output with shape [4, 1, 512, 512] doesn‘t match the broadcast shape[4, 4, 512, 512]
ROS series (IV): ROS communication mechanism series (3): parameter server
The art of concurrent programming (3): an in-depth understanding of the principle of synchronized
How to introduce opencv into cmake project
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
Three column layout (fixed width on both sides in the middle and fixed width on both sides in the middle)
How Zotero quotes in word jump to references / hyperlink
The whole process of connecting the newly created unbutu system virtual machine with xshell and xftp
Leetcode 617 merge binary tree
Xiaomi, qui a établi le plus grand volume de ventes de téléphones portables domestiques sur le marché d'outre - mer, se concentre de nouveau sur le marché intérieur