What is PhpSpreadsheet? how to use?
The previous article introduced you to "What is Ajax?" working principle? How to use Ajax to complete a GET request", this article continues to introduce to you what is PhpSpreadsheet? how to use? (Code attached) has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
PhpSpreadsheet introduction
##1. What is PhpSpreadsheet
- [info] PhpSpreadsheet is a library written in pure PHP that provides a set of classes that allow you to read and write different spreadsheet file formats
- PhpSpreadsheet provides a rich API interface, which can set many cell and document properties, including styles, pictures, dates, functions and many other applications. In short, PhpSpreadsheet can do whatever kind of Excel table you want
BIFF 5 (.xIs) Excel 95
SpreadsheetML (. xm) Excel 2003
Gnumeric
HTML
SYLK
CSV
3. PhpSpreadsheet official website
##●htps://phpspreadsheet.readthedocs.io
##4. PhpSpreadsheet installation
●composer require phpoffice/phpspreadsheet
We start to learn how to use PHPspreadsheet:
First we automatically load composer The file is loaded in, and this file can call all composer plug-ins. Then we reference this file, that is, give an alias, and then we instantiate the spreadsheet object; Let’s take the code as an example:
Automatically loaded file (autoload.php), as long as we introduce this file, it will automatically introduce all files under composer <?php
//autoload.php @egenerated by Composer
require_once_DIR__ . ' /composer/autoload_real. php';
return ComposerAutoloaderInitb97eea8e7b2e6edebfeef718a4689bd::getLoader();
●getActiveSheet
<?php #载入composer自动加载文件 require 'vendor/autoload.php' ; #给类文件的命名空间起个别名 use PhpOffice\PhpSpreadsheet\Spreadsheet; #实例化Spreadsheet 对象 $spreadsheet = new Spreadsheet(); #获取活动工作薄 ssheet = $spreadsheet->getActiveSheet();
3. Get cells
●Two ways to get cellsgetCell
getCellByColumnAndRow
- 4. Set cell
<?php #载入composer自动加载文件 require 'vendor/autoload . php'; #给类文件的命名空间起个别名 use PhpOffice\PhpSpreadsheet\Spreadsheet; #实例化Spreadsheet对象 $spreadsheet = new Spreadsheet(); #获取活动工作薄 ssheet = Sspreadsheet->getActiveSheet(); #获取单元格 $cell = $sheet->getcell('A1'); $ce1l = ssheet->getCel1ByColumnAndRow(1.1);
Copy after login ●setValue
Parameter: cell value
<?php #载入composer自动加载文件 require 'vendor/autoload.php'; #给类文件的命名空间起个别名 use PhpOffice\PhpSpreadsheet\Spreadsheet; #实例化Spreadsheet 对象 $spreadsheet = new Spreadsheet(); #获取活动工作薄 $sheet■$spreadsheet->getActiveSheet(); t获取单元格 $ce1lA = $sheet->getCe1l('A1'); #设置单元格值 $cellA->setValue('lili'); #获取单元格 $ce11B = $sheet->getCe11ByColumnAndRow(1,2); 设置单元格值 $cellB->setVa1ue('baby'); #获取设置单元格,链式操作 $sheet->getCell('A3')->setValue('axl'); $sheet->getCellByColumnAndRow(1,4)->setValue('boy');
5. Get the cell value
getValueGet the cell value
getCoordinate Gets the cell coordinates
<?php #载入composer 自动加载文件 require 'vendor/autoload. php'; #给类文件的命名空间起个别名 use PhpOffice\PhpSpreadsheet\Spreadsheet; #实例化Spreadsheet 对象 $spreadsheet = new Spreadsheet(); #获取活动工作薄 $sheet = $spreadsheet->getActiveSheet(); #获取单元格 $cellA = $sheet->getCell('A1'); #设置单元格值 $cel1A->setValue('baby'); echo '值: ',$cellA->getValue(),PHP_EOL; echo'坐标:',$cel1A->getCoordinate();
Copy after loginRecommended learning: "
PHP Video Tutorial"The above is the detailed content of What is PhpSpreadsheet? how to use?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
