PHP code example of asimlqt / php-google-spreadsheet-client

1. Go to this page and download the library: Download asimlqt/php-google-spreadsheet-client 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/ */

    

asimlqt / php-google-spreadsheet-client example snippets


use Google\Spreadsheet\DefaultServiceRequest;
use Google\Spreadsheet\ServiceRequestFactory;

$serviceRequest = new DefaultServiceRequest($accessToken);
ServiceRequestFactory::setInstance($serviceRequest);

$spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
$spreadsheetFeed = $spreadsheetService->getSpreadsheetFeed();

$spreadsheet = $spreadsheetFeed->getByTitle('MySpreadsheet');

$serviceRequest = new DefaultServiceRequest("");
ServiceRequestFactory::setInstance($serviceRequest);

$spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
$worksheetFeed = $spreadsheetService->getPublicSpreadsheet("spreadsheet-id");

$spreadsheet = $spreadsheetFeed->getByTitle('MySpreadsheet');
$worksheetFeed = $spreadsheet->getWorksheetFeed();

$worksheet = $worksheetFeed->getByTitle('Sheet1');

$spreadsheet->addWorksheet('New Worksheet', 50, 20);

$cellFeed = $worksheet->getCellFeed();

$cellFeed->editCell(1,1, "Row1Col1Header");
$cellFeed->editCell(1,2, "Row1Col2Header");

$worksheet->delete();

$listFeed = $worksheet->getListFeed();

foreach ($listFeed->getEntries() as $entry) {
    $values = $entry->getValues();
}

$listFeed = $worksheet->getListFeed(["sq" => "age > 45", "reverse" => "true"]);

$listFeed->insert(["name" => "Someone", "age" => 25]);

$entries = $listFeed->getEntries();
$listEntry = $entries[0];

$values = $listEntry->getValues();
$values["name"] = "Joe";
$listEntry->update($values);

$cellFeed = $worksheet->getCellFeed();

$cell = $cellFeed->getCell(10, 2);

$cell->update("=SUM(B2:B9)");

$cellFeed = $worksheet->getCellFeed();

$batchRequest = new Google\Spreadsheet\Batch\BatchRequest();
$batchRequest->addEntry($cellFeed->createCell(2, 1, "111"));
$batchRequest->addEntry($cellFeed->createCell(3, 1, "222"));
$batchRequest->addEntry($cellFeed->createCell(4, 1, "333"));
$batchRequest->addEntry($cellFeed->createCell(5, 1, "=SUM(A2:A4)"));

$batchResponse = $cellFeed->insertBatch($batchRequest);

curl -sS https://getcomposer.org/installer | php

php composer.phar install