码迷,mamicode.com
首页 > Web开发 > 详细

PhpSpreadSheet 读写excel文件

时间:2019-10-06 22:11:37      阅读:312      评论:0      收藏:0      [点我收藏+]

标签:off   latest   reader   actor   phpexcel   col   excel   value   code   

phpoffice 系列很好用。PhpSpreadSheet取代了原先的phpexcel,用来处理excel文件

https://phpspreadsheet.readthedocs.io/en/latest/

简单的使用示例:

1、基本操作

注意:新建和修改是不同的类来处理的

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\IReader;
use PhpOffice\PhpSpreadsheet\Writer\IWriter;

新建

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue(‘A1‘, ‘Hello World !‘);

$writer = new Xlsx($spreadsheet);
$writer->save(‘hello world.xlsx‘);

修改

$spreadsheet = IOFactory::load($old_file);
$worksheet = $spreadsheet->getActiveSheet();
// 修改
$worksheet->getCell(‘A1‘)->setValue(‘John‘);
$worksheet->getCell(‘A2‘)->setValue(‘Smith‘);

$writer = IOFactory::createWriter($spreadsheet, ‘Xlsx‘);
$writer->save($new_file);   

 

PhpSpreadSheet 读写excel文件

标签:off   latest   reader   actor   phpexcel   col   excel   value   code   

原文地址:https://www.cnblogs.com/mitang/p/11628682.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!