定制 mach3/google-spreadsheet 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

  1. Log in Google Developer Console
  2. Create new project
  3. Create Service Account credentials in the project
  4. Download key file as JSON

2. Create spreadsheet

  1. Create a new spreadsheet in Google Drive
  2. Authorize the email address, which is found as 'client_email' in key file, to read and edit.
  3. 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

mach3/google-spreadsheet 适用场景与选型建议

mach3/google-spreadsheet 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20.16k 次下载、GitHub Stars 达 32, 最近一次更新时间为 2015 年 09 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 mach3/google-spreadsheet 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mach3/google-spreadsheet 我们能提供哪些服务?
定制开发 / 二次开发

基于 mach3/google-spreadsheet 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 20.16k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 32
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 32
  • Watchers: 2
  • Forks: 13
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-09-03