gekkone/table-data-accessors
最新稳定版本:1.1.1
Composer 安装命令:
composer require gekkone/table-data-accessors
包简介
A common interface for accessing table data. Contains implementations for csv and google spreadsheets
README 文档
README
A common interface for accessing table data on PHP. Contains implementations for csv and google spreadsheets
Details
An extended iterator interface is provided to access tabular data.
src/TableIteratorInterface.php line 7:11
interface TableIteratorInterface extends Iterator { public function fetchRowCount(bool $skipEmpty = false): int; public function currentField(string $field, $default = null); }
⚠️ Attention: The data of the first row is used as keys in the associative array returned for each of the rows
Code Examples
Simple read from csv file:
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, ...] }
Simple read from Google Sheet
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, ...] }
This work is licensed under a Creative Commons Attribution 4.0 International License
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: CC-BY-4.0
- 更新时间: 2023-08-17