簡體   English   中英

Google Spreadsheet函數從所有工作表中獲取數據,而不僅僅是一個

[英]Google Spreadsheet function gets data from all sheets instead of just one

這是我編寫的功能,每當編輯指定的單元格/行/列時,它都會發送電子郵件通知某人,並且我將其設置為觸發onEdit。 它按原樣工作。

/* This function send an email when a specified range is edited
 * The spreadsheets triggers must be set to onEdit for the function
*/

function sendNotification() {
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var sheet = ss.getActiveSheet();
  //Get Active cell
      var mycell = ss.getActiveSelection();
      var cellcol = mycell.getColumn();
      var cellrow = mycell.getRow();
  //Define Notification Details
      var recipients = "me@email.com";
      var subject = "Update to "+ss.getName();
      var body = ss.getName() + "has been updated.  Visit " + ss.getUrl() + " to view the changes.";
  //Check to see if column is A or B to trigger
      if (cellcol == 1, 2)
      {
  //check for row to trigger
        if (cellrow == 1)
        {
  //Send the Email
      MailApp.sendEmail(recipients, subject, body);
      }
  //End sendNotification
 }
}

我的問題是,只有在編輯電子表格的某個工作表(頁面)上的列或行時,而不是電子表格中任何工作表的X列時,我才需要使用此選項。

有任何想法嗎? 我希望我錯過了一些簡單的事情,但是我一直找不到解決方案。

您可以在分配工作sheet變量后中斷該函數:

if (sheet.getSheetName() != 'SheetIWant') return;

您需要查看onEdit提供的參數。 它會告訴您更改發生的位置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM