Reputation: 305
i can update an cell value with Google Api?
already i can read all values from an google sheet, but i cant update any value.
i try this:
$body = new Google_Service_Sheets_ValueRange(array(
'values' => $locations
));
$params = array(
'valueInputOption' => $locations
);
$result2 = $service->spreadsheets_values->update($spreadsheetId, "A1", $body, $params);
print($result2);
but i get this error:
Fatal error: Uncaught Google_Service_Exception: {
"error": {
"code": 400,
"message": "Invalid value at 'data.values[0]' (type.googleapis.com/google.pr
otobuf.ListValue), \"Stant 1\"\nInvalid value at 'data.values[1]' (type.googleap
is.com/google.protobuf.ListValue), \"Stant 10\"\nInvalid value at 'value_input_o
ption' (TYPE_ENUM), \"\"",
"errors": [
{
"message": "Invalid value at 'data.values[0]' (type.googleapis.com/googl
e.protobuf.ListValue), \"Stant 1\"\nInvalid value at 'data.values[1]' (type.goog
leapis.com/google.protobuf.ListValue), \"Stant 10\"\nInvalid value at 'value_inp
ut_option' (TYPE_ENUM), \"\"",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}
Upvotes: 2
Views: 6083
Reputation: 305
ok thank you. I found the solution ->
$options = array('valueInputOption' => 'RAW');
http://ajaxray.com/blog/store-data-to-google-sheets-using-php/
$options = array('valueInputOption' => 'RAW');
$values = [
["Name", "Roll No.", "Contact"],
["Anis", "001", "+88017300112233"],
["Ashik", "002", "+88017300445566"]
];
$body = new Google_Service_Sheets_ValueRange(['values' => $values]);
$result = $service->spreadsheets_values->update(SHEET_ID, 'A1:C3', $body, $options);
print($result->updatedRange. PHP_EOL);
Upvotes: 3