来源:未知 时间:2020-12-22 16:41 作者:小飞侠 阅读:次
[导读] PHP如何操作Excel之phpspreadsheet教程 今天给大家带来一个php插件 phpspreadsheet 下载phpoffice/phpspreadsheet,地址:https://packagist.org/packages/phpoffice/phpspreadsheet composerrequirephpoffice/phpspreadsheet 如何使...
PHP如何操作Excel之phpspreadsheet教程 今天给大家带来一个php插件 phpspreadsheet 下载 phpoffice/phpspreadsheet,地址:https://packagist.org/packages/phpoffice/phpspreadsheet composer require phpoffice/phpspreadsheet 如何使用呢?请看下面DEMO 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'); |
自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习
京ICP备14009008号-1@版权所有www.zixuephp.com
网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com