承接 mach3/google-spreadsheet 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

mach3/google-spreadsheet

最新稳定版本:v1.1.0

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

统计信息

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

GitHub 信息

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

其他信息

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