PHP code example of chinahub / xls-writer

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

    

chinahub / xls-writer example snippets


use Chinahub\XlsWriter\interfaces\ExportInterface;

class UserExport implements ExportInterface
{
    public function headers(): array
    {
        return ['id','name','email'];
    }

    public function data(): array
    {
        return [
            [1,'tom','[email protected]'],
            [2,'lily','[email protected]'],
            [3,'lisa','[email protected]'],

        ];
    }
}

use Chinahub\XlsWriter\Export;

$excel = new Export(new UserExport());
$excel->config = ['path' => '/www'];
$excel->fileName = 'user.xlsx';
$excel->output();

use Chinahub\XlsWriter\Export;

$excel = new Export(new UserExport());
$excel->fileName = 'user.xlsx';
$excel->download();

use Chinahub\XlsWriter\Import;

$excel = new Import('/www/user.xlsx');
$excel->getSheet();

use Chinahub\XlsWriter\Import;

$excel = new Import('/www/user.xlsx');
$excel = $excel->instance();
while (($row = $excel->nextRow()) !== NULL) {
    var_dump($row);
}