PHP code example of gekkone / table-data-accessors

1. Go to this page and download the library: Download gekkone/table-data-accessors 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/ */

    

gekkone / table-data-accessors example snippets


  interface TableIteratorInterface extends Iterator
  {
      public function fetchRowCount(bool $skipEmpty = false): int;
      public function currentField(string $field, $default = null);
  }
  

use Gekkone\TdaLib\Accessor\Csv;
use GuzzleHttp\Psr7\Stream;

$accessor = new Csv(
    Csv\TableOptions::new(new Stream(fopen(__DIR__ . '/filename.csv', 'r')))
);

foreach ($accessor as $row => $fields) {
    // $fields = ['columnHeader' => mixed, ...] or [(int) columnIndex => mixed, ...]
}

use Gekkone\TdaLib\Accessor\GoogleSheet;
use Google\Client;
use Google\Service\Sheets;

$googleCline = new Client([
    'scopes' => Sheets::SPREADSHEETS_READONLY
]);

// for read first sheet
$accessor = new GoogleSheet(
    GoogleSheet\TableOptions::new(new Sheets($googleCline), 'spreadsheetId')
);

// for read concreate sheet set sheetId, find it in url after '#gid=',
// example https://docs.google.com/spreadsheets/d/<spreadsheetID>/edit#gid=1737163713)
$accessor = new GoogleSheet(
    GoogleSheet\TableOptions::new(new Sheets($googleCline), 'spreadsheetId', 1737163713)
);

foreach ($accessor as $row => $fields) {
    // $fields = ['columnHeader' => mixed, ...] or [(int) columnIndex => mixed, ...]
}