承接 survos/google-sheets-bundle 相关项目开发

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

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

survos/google-sheets-bundle

Composer 安装命令:

composer require survos/google-sheets-bundle

包简介

This bundle manages Google Spreadsheets using the Google api.

README 文档

README

Inspired by / Forked from https://github.com/Gabb1995/EXS-GoogleSheetsBundle

Useful references

EXS-GoogleSheetsBundle

Very simple wrapper for Google sheets integration

What is this bundle doing ?

This bundle provides basic Google API SpreadSheets Sheets Service methods as Symfony services.
Methods: Get|Create|Update|Clear|Delete

Usage

Configuration

  1. Set your Google project and get the client secret file.
    Click here to obtain your client secret and set project application name

  2. Save your client secret file as 'client_secret.json' in your project.

  3. Add the client secret file location, project application name and credential location in the Symfony config file

survos_google_sheets:
    application_name: 'Google Sheets API'
    credentials: '%kernel.root_dir%/config/sheets.googleapis.com.json'
    client_secret: '%kernel.root_dir%/config/client_secret.json'

Your credentials will be created by the bundle once you set the file location in the bundle.
Default location: '/Credentials/sheets.googleapis.com.json'

Create the access token

Create the access token for google api.

  1. Execute the service via the command line.
    The service will provide you the link to get a verification code.
bin/console googlesheets:execute --function=token
  1. Copy the verification code from the link then enter it in the command line.

Inputs

id: Spreadsheets id
title: sheet(tab) title
header: number of rows for header.
data: 2 dimensional array for grid data.

$data = [
    [ COL1_HEADER, COL2_HEADER, ...],
    [ ROW1COL1_CELL_VALUE, ROW1COL2_CELL_VALUE, ...],
    [ ROW1COL2_CELL_VALUE, ROW2COL2_CELL_VALUE, ...],
    ....
];

Methods

SETUP(Common for all methods).

Inject GoogleSheetsApiService or obtain it from the container.

ex) Set up an api client with the spreadsheets id that you want to manage.

    public function __construct(
        private readonly GoogleApiClientService $clientService,
        private readonly GoogleSheetsApiService $sheetService,
    )

$sheetService->setSheetServices(YOUR_SPREADSHEETS_ID_HERE);
GET

Get an existing spreadsheets

$spreadsheets = $service->getGoogleSpreadSheets(); 
CREATE

Create the new sheet in Google Spreadsheets.
Return: Number of data rows that are inserted to the new sheet.
If you call the function without data, it will create an empty sheet.

ex) Create the new sheet with data

$sheetTitle = 'my test sheet';
$data = [
    [ COL1_HEADER, COL2_HEADER, ...],
    [ ROW1COL1_CELL_VALUE, ROW1COL2_CELL_VALUE, ...],
    ....
];
$response = $service->createNewSheet($sheetTitle, $data);
UPDATE

Update the existing spreadsheets sheet.
Return: Number of data rows that are updated to the sheet.

If you wants to update only cell values, not the header, define number of rows for the header.
ex) Update grid data values only.

$header = 1;
$sheetTitle = 'my test sheet';
$data = [
    [ ROW1COL1_CELL_VALUE, ROW1COL2_CELL_VALUE, ...],
    [ ROW2COL1_CELL_VALUE, ROW2COL2_CELL_VALUE, ...],
    ....
];
$response = $service->updateSheet($sheetTitle, $data, $header);
CLEAR

Clear the entire sheet values.
Return: number of rows that are cleared.

$sheetTitle = 'my test sheet';
$response = $service->clearSheetByTitle($sheetTitle);
DELETE

Delete the existing sheet in the spreadsheets.
Return: Boolean

$sheetTitle = 'my test sheet';
$response = $service->deleteSheetByTitle($sheetTitle); 



Example

Create the new sheet with header then update it with data

// setup the service
$service = $this->getContainer()->get('survos_google_sheets.sheets_service');
$service->setSheetServices(YOUR_SPREADSHEETS_ID_HERE);

// create the sheet
$sheetTitle = 'my test sheet';
$data = [
    [ COL1_HEADER, COL2_HEADER, COL3_HEADER]
];
$service->createNewSheet($sheetTitle, $data);

// update grid data
$header = 1;
$data = [
    [ ROW1COL1_CELL_VALUE, ROW1COL2_CELL_VALUE, ROW1COL3_CELL_VALUE],
    [ ROW2COL1_CELL_VALUE, ROW2COL2_CELL_VALUE, ROW2COL3_CELL_VALUE],
    [ ROW3COL1_CELL_VALUE, ROW3COL2_CELL_VALUE, ROW3COL3_CELL_VALUE],
    [ ROW4COL1_CELL_VALUE, ROW4COL2_CELL_VALUE, ROW4COL3_CELL_VALUE]
];
$service->updateSheet($sheetTitle, $data, $header);

survos/google-sheets-bundle 适用场景与选型建议

survos/google-sheets-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 747 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 05 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「api」 「bundle」 「google」 「spreadsheets」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-05-17