标签:org pread off cti 实例 each nbsp class excel
1.下载 phpoffice/phpspreadsheet,地址:https://packagist.org/packages/phpoffice/phpspreadsheet
composer require phpoffice/phpspreadsheet
2.使用:
2.1读取文件:
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; //实例化 $xlsx = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx(); //加载文件 $excel = $xlsx->load("1.xlsx"); //获取活动的excel sheet $sheet = $excel ->getActiveSheet(); //获取sheet列数 $cols = $sheet->getHighestColumn(); //获取行数 $rows = $sheet->getHighestRow(); $data = []; for ($r=2;$r<=$rows;$r++){ //行 $tmp = []; for ($c = ‘A‘; $c <= $cols; $c++){ //列值 $tmp[]= $active->getCell($c.$r)->getValue(); } $data[] = $tmp; } //写入excel $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); foreach ($data as $key=>$val) { $key++; $sheet->setCellValue("A".$key,$val) ->setCellValue("B".$key,$val]) ...; } $writer = new Xlsx($spreadsheet); $writer->save(‘2.xlsx‘);
标签:org pread off cti 实例 each nbsp class excel
原文地址:https://www.cnblogs.com/itwlp/p/11109280.html