标签:off latest reader actor phpexcel col excel value code
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);
标签:off latest reader actor phpexcel col excel value code
原文地址:https://www.cnblogs.com/mitang/p/11628682.html