javascript - 使用谷歌应用程序脚本获取电子表格中一列的值

标签 javascript google-apps-script google-apps

我想获取一个字符串值,以便稍后使用 Google Apps 脚本将其与电子表格中仅一列的 if 条件进行比较。 我搜索了互联网,找到了这个链接 - 抱歉,如果这听起来很愚蠢,但我是 Google 应用脚本的新手 - https://developers.google.com/apps-script/class_spreadsheet

var values = SpreadsheetApp.getActiveSheet().getRange(2, 3, 6, 4).getValues(); 

我想这一定会有帮助,唯一的问题是我想要从中获取值的列是动态的,那么如何设置该列的范围?

最佳答案

如果您简单地使用:

var 值 = SpreadsheetApp.getActiveSheet().getDataRange().getValues()

您将获得工作表中按行和列索引的所有数据的二维数组。

因此,要获取第 1 列 A 列中的值,您可以使用 values[0][0] ,对第 2 行 A 列使用 values[1][0] , C 列 row1 的 values[0][2] 等...

如果您需要在 for 循环中进行迭代(在单列中):

for (n = 0; n < values.length; ++n) {
    var cell = values[n][x] ; // x is the index of the column starting from 0
}

如果您需要在 for 循环中迭代(在单行中):

for (n = 0; n < values[0].length; ++n) {
    var cell = values[x][n] ; // x is the index of the row starting from 0
}

关于javascript - 使用谷歌应用程序脚本获取电子表格中一列的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14991030/

相关文章:

javascript - 如何将 Google 脚本表单数据导出到 Google 云端硬盘?

javascript - 标题中带有文本的按钮的大小与内部带有图标的大小不同。为什么?

javascript - onClick td 内部元素的toggleClass 和同级td 内部元素的removeClass

javascript - 将 Observable 与 async/await 结合使用是一种好习惯吗?

asp.net - 使用 ASP.NET 创建简单的 Google 应用程序

python - 我们如何检查我们的应用程序是否为某些组织而不是所有组织安装?

javascript - 禁用在控制台中编辑 session 存储变量的可能性

google-apps-script - 对 bigquery.jobs.getQueryResults 的 API 调用失败,错误为 : Not found: Job

html - 在 Google Sheet 中使用 D3.js 可搜索可折叠树

google-apps-script - 在 Google Apps 脚本中构建应用程序的限制