Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 如何使用google脚本获取A2:A长度_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script 如何使用google脚本获取A2:A长度

Google apps script 如何使用google脚本获取A2:A长度,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我需要根据第一列输入(电子邮件ID)和(动态行,根据时间更新)从我的工作表发送电子邮件。如何使用google脚本仅返回A2:A长度。另外,我如何在excel中也能做到这一点 var formattedDate = Utilities.formatDate(new Date(), "GMT-6", "'Date: ' yyyy-MM-dd ' Time: ' HH:mm:ss ' CDT'"); var EMAIL_SENT = 'Email Success ! '+ "\n\n" +

我需要根据第一列输入(电子邮件ID)和(动态行,根据时间更新)从我的工作表发送电子邮件。如何使用google脚本仅返回A2:A长度。另外,我如何在excel中也能做到这一点

    var formattedDate = Utilities.formatDate(new Date(), "GMT-6", "'Date: ' yyyy-MM-dd ' Time: ' HH:mm:ss ' CDT'");

var EMAIL_SENT = 'Email Success ! '+ "\n\n" + formattedDate; 



/**
 * Sends non-duplicate emails with data from the current spreadsheet.
 */function sendEmails2() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Script (Beta)").activate();


  var startRow = 2; // First row of data to process
  var numRows = 120; // Number of rows to process

  // Fetch the range of cells 'A' columns

  var dataRange = sheet.getRange(startRow, 1, numRows, 3);
  // Fetch values for each row in the Range.

  var data = dataRange.getValues();

  for (var i = 0; i < data.length; ++i) {

    var row = data[i];
    var emailAddress = row[0]; // First column
    var message = row[1]; // Second column
    var emailSent = row[2]; // Third column


    if (emailSent !== EMAIL_SENT) { // Prevents sending duplicates

      var subject = '[Auto] The Process Has Not Yet Been Started';

      if(emailSent =='')
      break;

      MailApp.sendEmail(emailAddress, subject, message, {htmlBody: message,
                                                         cc: 'abc@xyz.com',
                                                         bcc:'cde@xyz.com'});

      sheet.getRange(startRow + i, 3).setValue(EMAIL_SENT);

      // Make sure the cell is updated right away in case the script is interrupted
      Logger.log(sendEmails2);
      SpreadsheetApp.flush();
    }}}
var formattedDate=Utilities.formattdate(新日期(),“GMT-6”,“日期:'yyyy-MM-dd'时间:'HH:MM:ss'CDT');
var EMAIL_SENT='EMAIL Success!'+“\n\n”+格式化日期;
/**
*发送包含当前电子表格数据的非重复电子邮件。
*/函数sendmails2(){
var sheet=SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“脚本(测试版)”).activate();
var startRow=2;//要处理的第一行数据
var numRows=120;//要处理的行数
//获取单元格“A”列的范围
var dataRange=sheet.getRange(startRow,1,numRows,3);
//获取范围中每行的值。
var data=dataRange.getValues();
对于(变量i=0;i
要获取“A”列的最后一行,可以首先获取该行的所有值:

var dataRange = sheet.getRange('A:A').getValues();
返回按行索引的二维值数组, 然后按列

因为我们已经将列设置为A,所以只需要一个
,就可以在数组中循环:

  var lastDataPosition = 0; // Create variable to set the last row of the column that has data

  for (var i = 0; i < dataRange.length; ++i) {
    if (dataRange[i] != '') { // Check if the array position has data
      lastDataPosition = i + 1 // If the position has data in it -> assign that position to 'lastDataPosition' as the last one
    }
  }
var lastDataPosition=0;//创建变量以设置包含数据的列的最后一行
对于(变量i=0;i将该职位分配给“lastDataPosition”作为最后一个职位
}
}
*我们将+1添加到数组位置,因为工作表的第一个单元格是1,数组的第一个位置是0

这是如何获得最后一行的数据,即使中间有一些空白单元格。

对于excel,我建议您使用正确的标签创建一个新问题。

我收到的错误是“缺少形式参数。(第8行,文件“test”)”
  var lastDataPosition = 0; // Create variable to set the last row of the column that has data

  for (var i = 0; i < dataRange.length; ++i) {
    if (dataRange[i] != '') { // Check if the array position has data
      lastDataPosition = i + 1 // If the position has data in it -> assign that position to 'lastDataPosition' as the last one
    }
  }