survos / google-sheets-bundle
This bundle manages Google Spreadsheets using the Google api.
Fund package maintenance!
kbond
Installs: 119
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.3
- google/apiclient: ^2.0
- symfony/config: ^6.4 || ^7.1
- symfony/console: ^6.4 || ^7.1
- symfony/dependency-injection: ^6.4 || ^7.1
- symfony/http-kernel: ^6.4 || ^7.1
Requires (Dev)
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^11.4
- rector/rector: dev-main
- dev-main
- 1.5.442
- 1.5.441
- 1.5.440
- 1.5.439
- 1.5.438
- 1.5.437
- 1.5.436
- 1.5.435
- 1.5.434
- 1.5.433
- 1.5.432
- 1.5.431
- 1.5.430
- 1.5.429
- 1.5.428
- 1.5.427
- 1.5.426
- 1.5.425
- 1.5.424
- 1.5.423
- 1.5.422
- 1.5.421
- 1.5.420
- 1.5.419
- 1.5.418
- 1.5.417
- 1.5.416
- 1.5.415
- 1.5.414
- 1.5.413
- 1.5.412
- 1.5.411
- 1.5.410
- 1.5.409
- 1.5.408
- 1.5.407
- 1.5.406
- 1.5.405
- 1.5.404
- 1.5.403
- 1.5.402
- 1.5.401
- 1.5.400
- 1.5.399
- 1.5.398
- 1.5.397
- 1.5.396
- 1.5.395
- 1.5.394
- 1.5.393
- 1.5.392
- 1.5.391
- 1.5.390
- 1.5.389
- 1.5.388
- 1.5.387
- 1.5.386
- 1.5.385
- 1.5.384
- 1.5.383
- 1.5.382
- 1.5.381
- 1.5.380
- 1.5.379
- 1.5.378
- 1.5.377
- 1.5.376
- 1.5.375
- 1.5.374
- 1.5.373
- 1.5.372
- 1.5.371
- 1.5.370
- 1.5.369
- 1.5.368
- 1.5.367
- 1.5.366
- 1.5.365
- 1.5.364
- 1.5.363
- 1.5.362
- 1.5.361
- 1.5.360
- 1.5.359
- 1.5.358
- 1.5.357
- 1.5.356
- 1.5.355
- 1.5.354
- 1.5.353
- 1.5.352
- 1.5.351
- 1.5.350
- 1.5.349
- 1.5.345
- 1.5.344
- 1.5.343
- 1.5.342
- 1.5.341
- 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-12-15 17:32:15 UTC
README
Inspired by / Forked from https://github.com/Gabb1995/EXS-GoogleSheetsBundle
Useful references
- 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
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
-
Set your Google project and get the client secret file.
Click here to obtain your client secret and set project application name -
Save your client secret file as 'client_secret.json' in your project.
-
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.
- 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
- 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);