PHP code example of ark4ne / xl-reader

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

    

ark4ne / xl-reader example snippets


$file = "my-calc.xlsx";

$reader = \Ark4ne\XlReader\Factory::createReader($file);

$reader->load();

foreach ($reader->read() as $row){
    // do stuff
}

/*
my-calc.xlsx
| A     | B     | C    |
| abc   | 123   | some |
*/
foreach ($reader->read() as $row){
    $row === [
        'A' => 'abc',
        'B' => '123',
        'C' => 'some',
    ];
}

/*
my-calc.xlsx
| A     | B     | C    |
| abc   |       | some |
*/

foreach ($reader->read() as $row){
    // do stuff
    $row === [
        'A' => 'abc',
        'C' => 'some',
    ];
}

/*
my-calc.xlsx
| A     | B     | C    |
| abc   |       | some |
*/

foreach ($reader->read() as $row){
    // do stuff
    $row === [
        'A' => 'abc',
        'B' => null,
        'C' => 'some',
    ];
}

$worksheets = $reader->getWorksheets();
/*
[
    ['id' => 1, 'name' => 'sheet 1'],
    ['id' => 2, 'name' => 'sheet 2'],
]
*/

$worksheet = $reader->getSelectedWorksheet();
/*
['id' => 1, 'name' => 'sheet 1'],
*/