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
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
<?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);
●setValue
<?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();
Recommended 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!