我正在尝试创建超过1000行的Google表格,并收到错误:
{
"error": {
"code": 400,
"message": "Invalid sheets[0].data[0]: Attempting to write row: 1000, beyond the last requested row of: 999",
"errors": [
{
"message": "Invalid sheets[0].data[0]: Attempting to write row: 1000, beyond the last requested row of: 999",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}
我还尝试创建一个空工作表,然后使用GridRanges运行批量更新调用。
$range = new Google_Service_Sheets_GridRange();
$range->setSheetId($sheetId);
$range->setStartRowIndex(0);
$range->setEndRowIndex(sizeof($data));
$range->setStartColumnIndex(0);
$range->setEndColumnIndex(sizeof(array_keys($data[0])));
$cellsRequest = new Google_Service_Sheets_UpdateCellsRequest();
$cellsRequest->setFields('*');
$cellsRequest->setRange($range);
$cellsRequest->setRows($rowDataArray);
$request = new Google_Service_Sheets_Request();
$request->setUpdateCells($cellsRequest);
$batchUpdate = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest();
$batchUpdate->setRequests(array($request));
$result = $service->spreadsheets->batchUpdate($documentId, $batchUpdate);
当它不起作用时,我尝试使用范围为1000条记录的UpdateCellRequests。这给了我这个错误:
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"update_cells\" at 'requests[0]': Proto field is not repeating, cannot start list.",
"errors": [
{
"message": "Invalid JSON payload received. Unknown name \"update_cells\" at 'requests[0]': Proto field is not repeating, cannot start list.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}
任何有关从哪里出发的帮助都会很棒!
谢谢。
答案 0 :(得分:3)
写入范围被截断为工作表的大小,而工作表只有1000行。您需要首先使用UpdateSheetPropertiesRequest或InsertDimensionRequest增加工作表中的行数。 (它可以在同一个batchUpdateSpreadsheet中调用。)
但这是一个非常误导性的错误信息,所以我会考虑让它变得更好。