用GoogleSheetsAPI

问题描述 投票:0回答:1

我可以使用Google API更新单元格值?

我可以从Google表中读取所有值,但我无法更新任何值。

我尝试一下:

$body = new Google_Service_Sheets_ValueRange(array( 'values' => $locations )); $params = array( 'valueInputOption' => $locations ); $result2 = $service->spreadsheets_values->update($spreadsheetId, "A1", $body, $params); print($result2);

但是我得到了这个错误:

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" } }

	
php google-sheets
1个回答
3
投票

$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);

	
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.