Last active
October 9, 2023 10:26
-
-
Save svamja/1357650b02f3ebcb4d631b24222ccb6a to your computer and use it in GitHub Desktop.
PHP Google Sheets API v4 - Working example to append rows with formatting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function append_rows_with_formatting($service, $sheet_id) { | |
$cell = [ | |
'userEnteredFormat' => [ | |
'numberFormat' => [ | |
'type' => 'NUMBER', | |
'pattern' => '[Color22]0.00', // '[Blue]#.##' | |
], | |
"backgroundColor" => [ | |
"red" => 0.2, | |
"green" => 1.0, | |
"blue" => 0.5, | |
], | |
], | |
'userEnteredValue' => [ | |
'numberValue' => 23 | |
], | |
'note' => 'previous value: 44' | |
]; | |
$cells = [ $cell, $cell ]; | |
$row = [ | |
'values' => $cells | |
]; | |
$rows[] = $row; | |
$appendCellsRequest = [ | |
'fields' => '*', | |
'rows' => $rows | |
]; | |
$request = [ | |
'appendCells' => $appendCellsRequest | |
]; | |
$batchUpdate = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest([ | |
'requests' => [ $request ] | |
]); | |
$service->spreadsheets->batchUpdate($sheet_id, $batchUpdate); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment