简体   繁体   中英

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?

I have an on edit function that sends an email when a column f is edited to a specific value. I need to find out the value in column b in order to include the value in the body of the message.

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. The row var is looking at the correct row. 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() . There are several ways to use 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()

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]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM