2
爲了使我的一些工作自動化,我開始學習谷歌腳本的基礎知識。需要爲多個列和工作表發送通知
我有一個電子表格,我想在數據輸入到一列或另一列時發送電子郵件通知。這個電子表格中還有兩個標籤,我希望發生這種情況。
該腳本的當前結果是第二個「sendnotification」函數的電子郵件。
問題:我如何拿到劇本要考慮兩者的功能?
我知道這個代碼可以通過更好的方式使用IF函數來縮小,但是我很茫然。
對於某些情況:這用於製造操作。生產是由一家非現場公司完成的,當他們將數量輸入到第10欄中的任何一張時,我希望它會向我的團隊發送一封與我合作的電子郵件。同樣,當產品質量測試完成後,我希望能夠輸入到第12欄,並向離線公司發送電子郵件。
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 = "[email protected]";
var subject = "Disc production was entered on the "+ss.getName();
var body = ss.getName() + " has been updated with an amount produced. Visit " + ss.getUrl() + " to view the quantities entered.";
//Check to see if column is A or B to trigger
if (cellcol == 10)
{
//Send the Email
MailApp.sendEmail(recipients, subject, body);
}
//End sendNotification
}
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 = "[email protected]";
var subject = "A lot of disc has been RELEASED by XYZ Company";
var body = ss.getName() + " has been updated with a lot of disc that were released by XYZ Company. Visit " + ss.getUrl() + " to view this updated information.";
//Check to see if column is A or B to trigger
if (cellcol == 12)
{
//Send the Email
MailApp.sendEmail(recipients, subject, body);
}
//End sendNotification
}
只是爲了澄清,你要自動發送的電子郵件,當你鍵入到第10列或列12?像'onedit'觸發器一樣? –
正確的,當數據被輸入到其中任何一列的自動電子郵件。 –