PHP code example of rekkles / easyexcel

1. Go to this page and download the library: Download rekkles/easyexcel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rekkles / easyexcel example snippets


use EasyExcel\Read\ExcelToArray;
use EasyExcel\Read\ChunkReadFilter;

//简单获取Excel的数据为Array
$config = ['firstRowAsIndex' => true];
$getData = new ExcelToArray('/Users/rekkles/code/data.csv',$config);
$getData->load();
var_dump($getData->getData());

//分批获取Excel的数据(防止内存泄漏)
$chunk = new ChunkReadFilter();
$chunk->setRows(10, 2);
$data = new ExcelToArray('/Users/rekkles/code/data.csv');
var_dump($data->loadByChunk($chunk)->getData());

//写入Excel 生成文件到指定目录
$outObj = new ArrayToExcel(array(
     'fileName' => 'test.csv',           //导出的excel的文件的名称
     'sheetTitle' => '11',              //每个工作薄的标题
     'creator' => 'rekkles',            //创建者
     'writeType' => 'CSV',              //输出类型 Excel5 Excel7 CSV
     'path' => ROOT_PATH.'file/',    //输出路径 确保有写入权限
));
$outObj->setFirstRow(array('',1111,2222,3333))
  ->fillData(array(
  ['','aaa','bbb','ccc'],
  ['','ddd','eee','fff']
  ));