mach3/google-spreadsheet
Composer 安装命令:
composer require mach3/google-spreadsheet
包简介
Google spreadsheet client
README 文档
README
Google Spreadsheet Client for PHP. This requires 'google/apiclient' package.
Get started
1. Get key file
- Log in Google Developer Console
- Create new project
- Create Service Account credentials in the project
- Download key file as JSON
2. Create spreadsheet
- Create a new spreadsheet in Google Drive
- Authorize the email address, which is found as 'client_email' in key file, to read and edit.
- Save the file ID from address bar.
3. Access by PHP
$client = Google_Spreadsheet::getClient('the/path/to/credential.json'); // Get the sheet instance by sheets_id and sheet name $sheet = $client->file('XXXxxxXXXXxxxXXXX')->sheet('Sheet1'); // Fetch data from remote (or cache) $sheet->fetch(); // Flush all rows in the sheet var_dump($sheet->items);
Usage
Initialize sheet (>= 1.1.0)
The target sheet must be empty
$sheet->init(array( 'id', 'name', 'age', 'email', 'note' ));
Select rows
// Array $items = $sheet->select(array( 'id' => '1' )); // Closure $items = $sheet->select(function($row){ return (int) $row['age'] < 30; });
Insert a new row
// Insert a new row $sheet->insert(array( 'name' => 'John', 'age' => 23, 'email' => 'john@example.com' )); // Get up-to-date items $items = $sheet->fetch(true)->items;
Update rows
// Update rows selected by array $sheet->update( array( 'email' => 'tom@example.com' ), array( 'name' => 'Tom' ) ); // Update rows selected by closure $sheet->update( array( 'email' => 'tom@example.com' ), function($row){ return $row['name'] === 'Tom'; } ); // Get up-to-date items $items = $sheet->fetch(true)->items;
Update cells (>=1.1.0)
edit method let you to update cells' value manually
// Update `B2` cell $sheet->edit(2, 2, 'Tom'); // Update `C1:C4` cells $sheet->edit(3, 1, array(1, 'John', 23, 'john@example.com'));
Get up-to-date table data
// Pass `true` to ignore cache $items = $sheet->fetch(true)->items;
Save cache option
$sheet->config(array( 'cache' => true, 'cache_dir' => __DIR__ . '/cache', 'cache_expires' => 360 ));
Requirement
- google/apiclient (Apache License v2.0)
mach3/google-spreadsheet 适用场景与选型建议
mach3/google-spreadsheet 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20.16k 次下载、GitHub Stars 达 32, 最近一次更新时间为 2015 年 09 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 mach3/google-spreadsheet 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mach3/google-spreadsheet 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 20.16k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 32
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-09-03