Skip to content

Instantly share code, notes, and snippets.

@etuardu
Created November 15, 2019 14:27
Show Gist options
  • Save etuardu/658be0364739963ba1cd3217ec6a98c0 to your computer and use it in GitHub Desktop.
Save etuardu/658be0364739963ba1cd3217ec6a98c0 to your computer and use it in GitHub Desktop.
agordi noton en ĉelo en gugla kalkultabelo
<?php
// ...
function setNoteRequest($sheetId, $cellRowIndex, $cellColumnIndex, $note) {
$cellData = new Google_Service_Sheets_CellData();
$cellData->setNote($note);
$rowData = new Google_Service_Sheets_RowData();
$rowData->setValues([$cellData]);
$rows[] = $rowData;
$gridRange = new Google_Service_Sheets_GridRange();
$gridRange->setSheetId($sheetId);
$gridRange->setStartRowIndex($cellRowIndex);
$gridRange->setEndRowIndex($cellRowIndex+1);
$gridRange->setStartColumnIndex($cellColumnIndex);
$gridRange->setEndColumnIndex($cellColumnIndex+1);
$fields = 'note';
$updateCellsRequest = new Google_Service_Sheets_UpdateCellsRequest();
$updateCellsRequest->setFields($fields);
$updateCellsRequest->setRows($rows);
$updateCellsRequest->setRange($gridRange);
$request = new Google_Service_Sheets_Request();
$request->setUpdateCells($updateCellsRequest);
return $request;
}
$client = getClient();
$service = new Google_Service_Sheets($client);
$spreadsheetId = '1zArSLe8dgPfblkkYTweiMzx9aJhR0mxEjn09dy0my6s';
// https://docs.google.com/spreadsheets/d/1zArSLe8dgPfblkkYTweiMzx9aJhR0mxEjn09dy0my6s/edit#gid=0
$sheetId = 0; // 1st sheet
$batchUpdate = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest();
$requests[] = setNoteRequest($sheetId, 0, 0, "noto en A1");
$requests[] = setNoteRequest($sheetId, 1, 4, "noto en E2");
$requests[] = setNoteRequest($sheetId, 2, 3, "noto en D3");
// cxi tie vi povas enpusxi en la array pliajn petojn, versxajne por
// aktualigi enhavon de cxeloj
// $requests[] = ...
$batchUpdate->setRequests($requests);
$service->spreadsheets->batchUpdate($spreadsheetId, $batchUpdate);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment