[英]How to find a column value within an active row
How do I find the data in a column within an active row that is already defined in Google Apps Script? 如何在Google Apps脚本中已定义的活动行内的列中查找数据?
I have an on edit function that sends an email when a column f is edited to a specific value. 我有一个on edit函数,当将f列编辑为特定值时会发送电子邮件。 I need to find out the value in column b in order to include the value in the body of the message.
我需要找出b列中的值,以便将该值包含在邮件正文中。
I have tried to use a range, but I am not understanding how i can define the second column for the active range that is already defined in the row variable. 我尝试使用范围,但是我不理解如何为行变量中已定义的活动范围定义第二列。 Here is what my code looks like.
这是我的代码的样子。 var called Values is the row of code I need help with.
名为“值”的var是我需要帮助的代码行。 The row var is looking at the correct row.
行var正在查看正确的行。 Any help is greatly appreciated.
任何帮助是极大的赞赏。
function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var sheetName = sheet.getName();
var cell = sheet.getActiveCell().getA1Notation();
var row = sheet.getActiveRange().getRow();
var cellvalue = sheet.getActiveCell().getValue().toString();
var values = row.getcell()[0,2].getvalue().toString();
var recipients = "kel...@trafficbuilders.us";
var message = '';
if(cellvalue === '✔'){
message = 'All Items have been received for .';
var subject = 'All Items have been received for ' ;
var body = message + ' Visit ' + ss.getUrl() + ' to view the changes';
MailApp.sendEmail(recipients, subject, body);
}
}
To fetch a certain data/value from a certain cell, here's what you can do: 要从特定单元格中获取特定数据/值,您可以执行以下操作:
First identify the cell where data is located using getRange() . 首先使用getRange()标识数据所在的单元格。 There are several ways to use getRange.
有几种使用getRange的方法。
Sample from the docs: 来自文档的示例:
// Get a range A1:D4 on sheet titled "Invoices"
var ss = SpreadsheetApp.getActiveSpreadsheet();
var range = ss.getRange("Sheet!A1:D4");
// Get cell A1 on the first sheet
var sheet = ss.getSheets()[0];
var cell = sheet.getRange("A1");
To actually fetch the content/data, use getValues() or getValue() 要实际获取内容/数据,请使用getValues()或getValue()
sample snippets: 样本片段:
// The code below gets the values for the range C2:G8
// in the active spreadsheet. Note that this is a JavaScript array.
var values = SpreadsheetApp.getActiveSheet().getRange(2, 3, 6, 4).getValues();
Logger.log(values[0][0]);
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Passing only two arguments returns a "range" with a single cell.
var range = sheet.getRange(1, 1);
var values = range.getValues();
Logger.log(values[0][0]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.