简体   繁体   English

如何在活动行中查找列值

[英]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.

相关问题 在值列中搜索单元格值以查找行号 - Search a cell value within a column of values to find row number 如何在行/列中查找值并返回其列/行号以存储为变量? - How to find a value in a row/column and return its column/row number to store as a variable? 如何避免根据同一日期范围内的列值插入一行数据? - How to avoid insertion of a row of data based on a column value within the same date range? 获取活动行并设置列 - Get Active row and set column 您能否使用 function 输入根据列和行中的值找到一个值? - Can you find a value based on value in column and row with a function input? 如何在 sheet1 的 I 列中找到非空白值,然后复制整行并粘贴到 sheet2 - How to find the non-blank value in column I in sheet1 then copy entire row and paste to sheet2 Google App Scripts:如何在行中找到第一个空单元格,检查下一列中的值并相应地设置值 - Google App Scripts: How to find first empty cell in row, check value in next column and set values accordingly 如何查找元素并获取行或列 - How to find element and get row or column 查找包含某些值的行号和列,然后将值插入该单元格 - Find Row Number and Column that contain certain values, then insert value into that cell 在列 google app 脚本中查找行并设置值 - Find row and set value in column google app scripts
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM