如何在谷歌脚本中获取特定单元格的内容

How to get the contents of specific cells in Google Scripting?

本文关键字:单元格 获取 谷歌 脚本      更新时间:2023-09-26

我有一个使用Google电子表格创建的电子表格。它是为了参加会议。每个会议都有一个值,所有值加在一起得到一个总数。我想要一个开关语句,上面写着,

for(i=0;i<columns.length;i++){
  if(cell in each column contains 'X'){
    switch(column[i])
        case 1:
            column[0]=meeting1;
            pointValue=5;
            break;
        case 2:
            column[1]=meeting2;
            pointValue=3;
            break;
  }
// add all the points up and place them next to the name in another spreadsheet

上面的代码都是伪的。

从本质上讲,我如何"获取"Google脚本中的特定单元格?

简短的回答是:

var dataRange = sheet.getRange(1, 1, numRows, numCols);
// and later, when you wish to update these cells
dataRange.setValues(newData);

如需更多尝试 https://github.com/greenido/AppsScriptBests - 这是一个我尝试通过好示例保持更新的存储库。