引用类:

use PhpOffice\PhpSpreadsheet\IOFactory;

use PhpOffice\PhpSpreadsheet\Cell\Coordinate;

use PhpOffice\PhpSpreadsheet\Spreadsheet;

use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

 

导入:

$inputFileType = IOFactory::identify($file_url); //传入Excel路径

            $excelReader   = IOFactory::createReader($inputFileType); //Xlsx

            $PHPExcel      = $excelReader->load($file_url); // 载入excel文件

            $sheet         ); // 读取第一個工作表

            $sheetdata = $sheet->toArray();

            return $sheetdata; // 返回数组数据

 

导出:

      $Excel['fileName']="ThinkPHP导出spreadsheet示例-".date('Y年m月d日-His',time());//or $xlsTitle

            $Excel['cellName']=['A','B','C','D'];

            $Excel['H'] = ['A'=>12,'B'=>20,'C'=>14,'D'=>16];//横向水平宽度

            $Excel['V'] = ['1'=>40,'2'=>23];//纵向垂直高度

            $Excel['sheetTitle']="spreadsheet示例";//大标题,自定义

            $Excel['xlsCell']=[['autoid','序号'],['school','学校'],['addr','省份'],['type','类型']];

                    Spread::excelPut($Excel,$this->getData());

 

 

 

文章来源:刘俊涛的博客
欢迎关注公众号、留言、评论,一起学习。

__________________________________________________________________________________

若有帮助到您,欢迎捐赠支持,您的支持是对我坚持最好的肯定(*^_^*)

05-22 15:58