survos / google-sheets-bundle
该捆绑包使用Google API管理Google电子表格。
Requires
- php: >=8.2
- google/apiclient: ^2.0
- symfony/config: ^6.4 || ^7.0
- symfony/console: ^6.4 || ^7.0
- symfony/dependency-injection: ^6.4 || ^7.0
- symfony/http-kernel: ^6.4 || ^7.0
Requires (Dev)
- phpstan/phpstan: ^1.11
- phpunit/phpunit: ^11.1
- rector/rector: ^1.1
- dev-main
- 1.5.340
- 1.5.339
- 1.5.338
- 1.5.337
- 1.5.336
- 1.5.335
- 1.5.334
- 1.5.333
- 1.5.332
- 1.5.331
- 1.5.330
- 1.5.329
- 1.5.328
- 1.5.327
- 1.5.326
- 1.5.325
- 1.5.324
- 1.5.323
- 1.5.322
- 1.5.321
- 1.5.320
- 1.5.319
- 1.5.318
- 1.5.317
- 1.5.316
- 1.5.315
- 1.5.314
- 1.5.313
- 1.5.312
- 1.5.311
- 1.5.310
- 1.5.309
- 1.5.308
- 1.5.307
- 1.5.306
- 1.5.305
- 1.5.304
- 1.5.303
- 1.5.302
- 1.5.301
- 1.5.300
- 1.5.299
- 1.5.298
- 1.5.297
- 1.5.296
- 1.5.295
- 1.5.294
- 1.5.293
- 1.5.292
- 1.5.291
- 1.5.290
- 1.5.289
- 1.5.288
- 1.5.287
- 1.5.286
- 1.5.285
- 1.5.284
- 1.5.283
- 1.5.282
- 1.5.281
- 1.5.280
- 1.5.279
- 1.5.278
- 1.5.277
- 1.5.276
- 1.5.275
- 1.5.274
- 1.5.273
- 1.5.272
- 1.5.271
- 1.5.270
- 1.5.269
- 1.5.268
- 1.5.267
- 1.5.266
- 1.5.265
- 1.5.264
- 1.5.263
- 1.5.262
- 1.5.261
- 1.5.260
- 1.5.259
- 1.5.258
- 1.5.257
- 1.5.256
- 1.5.255
- 1.5.254
- 1.5.253
- 1.5.252
- 1.5.251
- 1.5.250
- 1.5.249
- 1.5.248
- 1.5.247
- 1.5.246
- 1.5.245
- 1.5.244
- 1.5.243
- 1.5.242
- 1.5.241
- 1.5.240
- 1.5.239
- 1.5.238
- 1.5.237
- 1.5.236
- 1.5.235
- 1.5.234
- 1.5.233
- 1.5.232
- 1.5.231
- 1.5.230
- 1.5.229
- 1.5.228
- 1.5.227
This package is auto-updated.
Last update: 2024-09-24 13:45:06 UTC
README
灵感来自 / 分支自 https://github.com/Gabb1995/EXS-GoogleSheetsBundle
有用参考
- https://mzonline.com/blog/2020-06/pushing-data-google-sheets-sheets-yes-multiples
- https://developers.google.com/sheets/api/guides/values
- https://developers.google.com/sheets/api/quickstart/js
- https://www.lido.app/tutorials/google-sheets-group-tabs
EXS-GoogleSheetsBundle
非常简单的Google电子表格集成包装器
这个捆绑包在做什么?
此捆绑包将Google API电子表格服务的基本方法作为Symfony服务提供。
方法:获取|创建|更新|清除|删除
用法
配置
-
设置您的Google项目并获取客户端密钥文件。
点击此处获取客户端密钥并设置项目应用程序名称 -
将客户端密钥文件保存为'client_secret.json'到您的项目中。
-
在Symfony配置文件中添加客户端密钥文件位置、项目应用程序名称和凭证位置
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'
设置捆绑包中的文件位置后,捆绑包将创建凭证。
默认位置: '/Credentials/sheets.googleapis.com.json'
创建访问令牌
创建Google API的访问令牌。
- 通过命令行执行服务。
服务将为您提供获取验证码的链接。
bin/console googlesheets:execute --function=token
- 从链接复制验证码,然后将其输入到命令行中。
输入
id: 电子表格id
title: 表格(选项卡)标题
header: 表头行数。
data: 网格数据的二维数组。
$data = [ [ COL1_HEADER, COL2_HEADER, ...], [ ROW1COL1_CELL_VALUE, ROW1COL2_CELL_VALUE, ...], [ ROW1COL2_CELL_VALUE, ROW2COL2_CELL_VALUE, ...], .... ];
方法
SETUP(所有方法通用)。
注入GoogleSheetsApiService或从容器中获取它。
例如:使用要管理的电子表格ID设置API客户端。
public function __construct( private readonly GoogleApiClientService $clientService, private readonly GoogleSheetsApiService $sheetService, ) $sheetService->setSheetServices(YOUR_SPREADSHEETS_ID_HERE);
GET
获取现有的电子表格
$spreadsheets = $service->getGoogleSpreadSheets();
CREATE
在Google电子表格中创建新表格。
返回:插入到新表格中的数据行数。
如果您不提供数据调用函数,它将创建一个空表格。
例如:创建包含数据的表格
$sheetTitle = 'my test sheet'; $data = [ [ COL1_HEADER, COL2_HEADER, ...], [ ROW1COL1_CELL_VALUE, ROW1COL2_CELL_VALUE, ...], .... ]; $response = $service->createNewSheet($sheetTitle, $data);
UPDATE
更新现有的电子表格表格。
返回:更新到表格中的数据行数。
如果您只想更新单元格值,而不是表头,请定义表头行数。
例如:仅更新网格数据值。
$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
清除整个表格的值。
返回:清除的行数。
$sheetTitle = 'my test sheet'; $response = $service->clearSheetByTitle($sheetTitle);
DELETE
删除电子表格中的现有表格。
返回:布尔值
$sheetTitle = 'my test sheet'; $response = $service->deleteSheetByTitle($sheetTitle);
示例
创建带表头的表格,然后更新它以包含数据
// 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);