PHP code example of survos / google-sheets-bundle

1. Go to this page and download the library: Download survos/google-sheets-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

survos / google-sheets-bundle example snippets

 php
$data = [
    [ COL1_HEADER, COL2_HEADER, ...],
    [ ROW1COL1_CELL_VALUE, ROW1COL2_CELL_VALUE, ...],
    [ ROW1COL2_CELL_VALUE, ROW2COL2_CELL_VALUE, ...],
    ....
];
 php
    public function __construct(
        private readonly GoogleApiClientService $clientService,
        private readonly GoogleSheetsApiService $sheetService,
    )

$sheetService->setSheetServices(YOUR_SPREADSHEETS_ID_HERE);
 php
$spreadsheets = $service->getGoogleSpreadSheets(); 
 php
$sheetTitle = 'my test sheet';
$data = [
    [ COL1_HEADER, COL2_HEADER, ...],
    [ ROW1COL1_CELL_VALUE, ROW1COL2_CELL_VALUE, ...],
    ....
];
$response = $service->createNewSheet($sheetTitle, $data);
 php
$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);
 php
$sheetTitle = 'my test sheet';
$response = $service->clearSheetByTitle($sheetTitle);
 php
$sheetTitle = 'my test sheet';
$response = $service->deleteSheetByTitle($sheetTitle);