[英]How to pull a different value from google sheets each time it runs
So I am trying to pull the value that is in the latest line of google sheets
. 因此,我试图提取google sheets
的最新行中的值。 Here is the part of the script that I am having trouble with. 这是我遇到麻烦的脚本部分。 This script is being written within google scripts. 该脚本是用Google脚本编写的。
When this script runs the confirmation email it sends has the value of var cell as undefined
. 当此脚本运行确认电子邮件时,它发送的var单元格值为undefined
。 0 0
function formSubmitReply(e) {
var userEmail = e.values[3];
var sheet = SpreadsheetApp.getActiveSheet();
var lastRow = sheet.getLastRow();
// Set the status of the new ticket to 'New'.
// Column F is the Status column
sheet.getRange(lastRow, getColIndexByName("Status")).setValue("New");
var supportEmail;
// Calculate how many other 'New' tickets are ahead of this one
var numNew = 0;
for (var i = 2; i < lastRow; i++) {
if (sheet.getRange(i, getColIndexByName("Status")).getValue() == "New") {
numNew++;
}
}
var range = sheet.getRange("B2:B100");
var values = SpreadsheetApp.getActiveSheet().getDataRange().getValues()
Logger.log(values[0][0]);
for(n=0;n<values[0].length;++n){
var cell = values[n][1]
}
The problem is here: 问题在这里:
for(n=0;n<values[0].length;++n){
var cell = values[n][1]
}
values[0].length is the number of columns while values[n][1] goes through rows. values [0] .length是值[n] [1]通过行时的列数。
if you need a loop to go over the rows use this: 如果您需要循环遍历行,请使用以下命令:
for(n=0;n<values.length;++n){
var cell = values[n][1]
}
Otherwise if you have 10 columns and 50 rows, your loop will only go up to ten as values[0].length is 10 and you will pull data from: 否则,如果您有10列和50行,则循环将最多增加十个值[0]。length为10,您将从以下位置提取数据:
and etc until 等直到
and then loop will stop. 然后循环将停止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.