You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

解决Sheets API获取大型数据集时的413错误及数据清理问题

使用Sheets API处理40万行大型数据集时的分批清理问题

我正在开展一个项目,尝试使用Sheets API获取包含约40万行、11列的大型数据集。我了解到可通过分批次(如每次10万行)加载数据,但不知如何在分批处理时完成数据清理——需要遍历行并移除Content列值属于36个指定值之一的行。以下是我尝试的脚本,但在获取大型数据集的dataSourceArr时遇到413错误,同时附上待排除数据、大型数据集及预期结果示例:

//Data from Content Column. These are the excluded items
excludedContentArr = Sheets.Spreadsheets.Values.get(tss.getId(), `'` + excludedContentSht.getName() + `'!A2:A`).values;  

//This is the large dataset that is giving me an error right now
dataSourceArr = Sheets.Spreadsheets.Values.get(sourceSS.getId(), `'` + dataSourceSht.getName() + `'!A1:` + columnToLetter(dataSourceSht.getLastColumn())).values;
var headersDataSrcArr = dataSourceArr[0];//Get the first and only inner array
var eidDataSrcCN = headersDataSrcArr.indexOf('EID') + 1;//Arrays are zero indexed- add 1.
var contentDataSrcCN = headersDataSrcArr.indexOf('Content') + 1;//Arrays are zero indexed- add 1.
var statusDataSrcCN = headersDataSrcArr.indexOf('Status') + 1;//Arrays are zero indexed- add 1.
var compDateDataSrcCN = headersDataSrcArr.indexOf('Completion Date') + 1;//Arrays are zero indexed- add 1.
var pathwayDataSrcCN = headersDataSrcArr.indexOf('Pathway') + 1;//Arrays are zero indexed- add 1.

var values = [];
for(var i in dataSourceArr){    
  var excludedContentIndex = excludedContentArr.map(r => r[0]).indexOf(dataSourceArr[i][contentDataSrcCN-1]);
  if(excludedContentIndex == -1){
    //Action if not found
    values.push([
      dataSourceArr[i][eidDataSrcCN-1],
      dataSourceArr[i][contentDataSrcCN-1],
      dataSourceArr[i][statusDataSrcCN-1],
      dataSourceArr[i][compDateDataSrcCN-1],
      dataSourceArr[i][pathwayDataSrcCN-1]
    ]);
  }
}
Logger.log('Found ' + values.length + ' rows of data that met the criteria.');

//Paste into the destination sheet.
Sheets.Spreadsheets.Values.update({ values }, tss.getId(), `'` + pathwayContentCompSht.getName() + `'!A2`, { valueInputOption: "USER_ENTERED" });

待排除数据示例

Content
Back to the Future 1
Back to the Future 2
Back to the Future 3

大型数据集示例

EIDContentStatusCompletion DatePathway
a1Rocky 5Complete01/01/2024abc123
a2Back to the Future 1Complete01/01/2024abc123
a3Rocky 4Complete01/01/2024abc123
a4Rocky 3Complete01/01/2024abc123
a5Back to the Future 2Complete01/01/2024abc123
a6Rocky 2Complete01/01/2024abc123
a7Rocky 1Complete01/01/2024abc123
a8Matrix RevolutionsComplete01/01/2024abc123
a9Back to the Future 3Complete01/01/2024abc123
a10MatrixComplete01/01/2024abc123

预期结果示例

EIDContentStatusCompletion DatePathway
a1Rocky 5Complete01/01/2024abc123
a3Rocky 4Complete01/01/2024abc123
a4Rocky 3Complete01/01/2024abc123
a6Rocky 2Complete01/01/2024abc123
a7Rocky 1Complete01/01/2024abc123
a8Matrix RevolutionsComplete01/01/2024abc123
a10MatrixComplete01/01/2024abc123

内容的提问来源于stack exchange,提问作者DanCue

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 14:57:06