gpt4 book ai didi

google-sheets-api - 调用Sheet API时获取 "This action would increase the number of cells in the worksheet above the limit of 2000000 cells"

转载 作者:行者123 更新时间:2023-12-03 15:04:49 24 4
gpt4 key购买 nike

我正在使用 Google Sheets V4 append API将数据插入到新创建的工作表中。我正在插入 1000 行和 1001 列的数据,即 1001000 个单元格。

String url = https://sheets.googleapis.com/v4/spreadsheets/<spreadSheetId>/values/<workSheetName>!A1:append?access_token=<accessToken>&valueInputOption=USER_ENTERED&insertDataOption=INSERT_ROWS
//CREATING THE REQUEST BODY
reqBody.put("range", <workSheetName>+"!A1");
reqBody.put("majorDimension", "ROWS");
reqBody.put("values", <values>);

我收到 400 Bad Request与消息:

This action would increase the number of cells in the worksheet above the limit of 2000000 cells



我知道谷歌每张纸有 200 万个单元格限制,但我无法找出为什么我会收到此异常,特别是因为我没有超过限制。

关于为什么会发生此错误的任何帮助?

最佳答案

谷歌似乎对已经存在的细胞进行计数,即使它们是空白的 , 即使在全新的电子表格中 .解决方案是先删除这些列。您可以通过选择一列、右键单击并选择删除来手动执行此操作。

使用API​​,需要deleteDimension - 这是一个 PHP 示例:

        new Google_Service_Sheets_Request([
"deleteDimension" => [
"range" => [
"sheetId" => $sheetId,
"dimension" => "COLUMNS",
"startIndex" => 1,
"endIndex" => 26
],
],
]);

笔记:
  • 谷歌有不同寻常的语法来指示范围——第一列确实从 0 开始,但结束列需要是你想要的那一列,所以 0-1 是 A 列,而不是 A 和 B。
  • 在本例中,我们删除除第一列之外的所有内容 - 它不会让您删除整个工作表,例如如果你做 0-26(即所有这些),你会得到:

  • Invalid requests[1].deleteDimension: You can't delete all the columns on the sheet.


  • 不用担心,虽然您现在只有一列,但在您添加数据时会自动添加您需要的任意数量的新列
  • 我在 2019 年 12 月获得的工作簿限制是 5,000,000,而不是 2,000,000:

  • Invalid requests[2].pasteData: This action would increase the number of cells in the workbook above the limit of 5000000 cells.

    关于google-sheets-api - 调用Sheet API时获取 "This action would increase the number of cells in the worksheet above the limit of 2000000 cells",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46191772/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com