您现在的位置是:网站首页>软件开发>开发终端>thinkphpthinkphp

TP6操作excel--PhpSpreadsheet (1)表头设置

风口下的猪2021-12-02thinkphp

简介

首先实例化excel

$spreadsheet=new Spreadsheet();
$sheet=$spreadsheet->getActiveSheet();


表头列的宽度设置和标题设置,是依据 'A' 到 'Z' 来设置

一 .宽度

1.设置固定宽度

$sheet->getColumnDimension($titleColumn)->setWidth($width);

$titleColumn是字符类型,值为'A'--'Z'任意字符,表示该列

$width是number类型,值代表字符个数

2.设置自适应宽度

$sheet->getColumnDimension($titlecolumn)->setAutoSize(true);


二.标题

标题其实就是设置第一行的值

$sheet->setCellValue($titlecolumn.'1',$title);

$titleColumn是字符类型,值为'A'--'Z'任意字符,表示该列

$title是字符r类型,值为标题


$title = [
    ['title'=>'id','width'=>'30'],
    ['title'=>'姓名','width'=>'140'],
    ['title'=>'年龄','width'=>'40'],
    ['title'=>'性别','width'=>'40']
];
$titCol = 'A';
foreach ($title as $value) {
    //单元格内容写入
    $sheet->setCellValue($titCol . '1', $value['title']);
    //单元格设置宽度
    $sheet->getColumnDimension($titCol)->setWidth($value['width']);
    $titCol++;
}  







很赞哦! (0)

  • 软件开发
  • 素质要求
  • 计算机基础
  • 架构
  • 安全
  • 性能
  • 运维
  • 尾页
  • 数据库
  • 开发终端
  • 语言基础
  • 项目管理
  • 产品设计
  • 系统
  • 工作规范
  • 计算机网络
  • 前端技术栈
  • 数据结构
  • 计算机组成原理
  • 后端技术栈
  • 性能优化
  • 安全设计
  • 常见模块
  • 计算机操作系统
  • 服务器
  • python
  • MySQL
  • thinkphp
  • PHP
  • Java
  • JavaScript
  • Windows
  • Linux
  • 特效
  • indexedDB
  • vue
  • 淘宝联盟
  • Ionic
  • Angular
  • 微信小程序
  • 支付宝小程序
  • uni-app
  • css/sass/less
  • 支付
  • socket
  • 爬虫
  • web性能优化
  • 消息推送
  • CVM
  • sqlite
  • Redis
  • 前端基础
  • 基础
  • element
  • Nginx
  • yii2
  • /ponder/index.php/index/catelist/catelist/cateid/10.html

    相关阅读 (同一栏目)

    << /

    标签云

    站点信息

    • 文章统计:528篇
    • 移动端访问:扫码进入SQ3R