php表格 单元格,实例演示PhpSpreadsheet的单元格设置教程

favicon.ico摘要:PhpSpreadsheet是PHPExcel的升级版本,也就是说PHPExcel有的功能,PhpSpreadsheet也都可以实现,而且PHPExcel已经不再维护了,所以在以后要操作excel将要使用PhpSpreadsheet。

PhpSpreadsheet is the next version of PHPExcel. It breaks compatibility to dramatically improve the code base quality (namespaces, PSR compliance, use of latest PHP language features, etc.).

Because all efforts have shifted to PhpSpreadsheet, PHPExcel will no longer be maintained. All contributions for PHPExcel, patches and new features, should target PhpSpreadsheet master branch.

下面就通过实例来演示 PhpSpreadsheet 如何设置单元格。

1、在项目中引入PhpSpreadsheet

在PhpSpreadsheet中使用的是命名空间,最好可以通过composer引入:composer require phpoffice/phpspreadsheet

PHP version 7.1 or newer to develop using PhpSpreadsheet. Other requirements, such as PHP extensions, are enforced by composer.

官方文档也说了,需要用composer引入,不过值得一提的是,PhpSpreadsheet的使用要求php的版本在7.1以上。

PhpSpreadsheet的核心文件在src文件夹中,我们在使用它操作excel时,用的也都是这文件里面的类。

20191126_1574762208311197.png

2、实例演示<?php

//如果你的项目中不能自动引用,通过composer安装后在vendor文件夹下有个autoload.php文件

//在项目中引入autoload.php 文件就可以通过使用命名空间引入 PhpSpreadsheet 相关的功能类

require_once 'vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Spreadsheet;

use PhpOffice\PhpSpreadsheet\Style\Color;       //设置字体颜色

use PhpOffice\PhpSpreadsheet\Style\Alignment;   //设置对齐方式

use PhpOffice\PhpSpreadsheet\Styl

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值