简体   繁体   English

getValue() function 未在 Google Scripts for Sheets 中返回任何内容

[英]getValue() function not returning anything in Google Scripts for Sheets

I'm trying to use google scripts to select a random row from google sheets and return some of the cell values in those rows to email to me.我正在尝试使用谷歌脚本 select 来自谷歌表格的随机行并将这些行中的一些单元格值返回给我 email 。

Here's what I have so far:这是我到目前为止所拥有的:

function sendEmails() {

  var ss = SpreadsheetApp.openById('x');
  var sheet = ss.getSheetByName('report');

  var numRows = sheet.getLastRow();
  var randomRow = Math.floor(Math.random() * numRows); 

  var bodyTitle = sheet.getRange(3, randomRow).getValue();
  var bodyHighlight = sheet.getRange(4, randomRow).getValue();
  var bodyLink = SpreadsheetApp.getActiveSheet().getRange(2, randomRow).getValue();
  
  // var bodyTest = SpreadsheetApp.getActiveSheet().getRange(2, 2).getValue();

  var body = bodyTitle + " | " + bodyLink + " | " + bodyHighlight ; 
  var recipient = "x@gmail.com";
  var subject = "resurfaced highlights";

  MailApp.sendEmail(recipient, subject, body);

}

However when I receive the email all I get in the body is "| |"但是,当我收到 email 时,我得到的只是“| |” which makes it seem as though the getValue() functions for the bodyTitle, bodyHighlight, and bodyLink variables are not working.这使得 bodyTitle、bodyHighlight 和 bodyLink 变量的 getValue() 函数似乎不起作用。 Any help would be appreciated!任何帮助,将不胜感激!

Thanks.谢谢。

The problem is in the order of the parameters.问题在于参数的顺序。

It is supposed to be getRange(row, column) not getRange(column, row)它应该是getRange(row, column)而不是getRange(column, row)

Just swap the order of the parameters.只需交换参数的顺序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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