PHP code example of ciniran / yii2-excel

1. Go to this page and download the library: Download ciniran/yii2-excel 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/ */

    

ciniran / yii2-excel example snippets


php composer.phar 

     $array = [
            [
                'name'=>'tom',
                'age'=>18,
            ],
            [
                'name'=>'jerry',
                'age'=>19,
            ],
        ];
        $excel = new SaveExcel([
            'array' => $array,
            'headerDataArray' => ['name', 'age'],
        ]);
        $excel->arrayToExcel();


       $path = 'user.xlsx';
        $excel = new ReadExcel([
            'path' => $path,
            'head' => true,
            'headLine' => 1,
        ]);
        $data = $excel->getArray();

php composer.phar 

     $array = [
            [
                'name'=>'tom',
                'age'=>18,
            ],
            [
                'name'=>'jerry',
                'age'=>19,
            ],
        ];
        $excel = new SaveExcel([
            'array' => $array,
            'headerDataArray' => ['name', 'age'],
        ]);
        $excel->arrayToExcel();


       $path = 'user.xlsx';
        $excel = new ReadExcel([
            'path' => $path,
            'head' => true,
            'headLine' => 1,
        ]);
        $data = $excel->getArray();