PHP code example of irain / export-excel

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

    

irain / export-excel example snippets

 
    use Irain\ExportExcel\Export;  
    $config = [
        'cache_driver' => [
            'name'   => 'redis',
            'server' => '127.0.0.1',
            'port'   => '6379',
        ],
        'path'         => DOWNLOAD_PATH,
        'writer'       => 'excel', // if empty default writer is `excel`
    ];

    $excelData = [
        ['green', '1']
    ];

    $fileName = 'export_file_name' . date('Y-m-d H:i:s', time());

    $export   = new Export($config);

    $export->fileName($fileName)
        ->header(['name', 'age'])
        ->data($excelData)
        ->output();
 

    use Irain\ExportExcel\Import;  
    $importConfig = [
        'cache_driver' => [
            'name'   => 'redis',
            'server' => '127.0.0.1',
            'port'   => '6379',
        ],
        'writer'       => 'excel', // if empty default writer is `excel`
    ];

    $import = new \Irain\ExportExcel\Import($importConfig);
    $data = $import->setResource('/var/www/html/export_file_name.xls')
    ->header(['name', 'age'])
    ->resourceToArray();