1

我剛剛使用Google文檔腳本編輯器,因此請客氣。這是我到目前爲止有:電子郵件通知問題

function onEdit(e) { 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    var sheet = ss.getActiveSheet(); 

    //Get Active cell 
    var mycell = ss.getActiveSelection(); 
    var cellcol = mycell.getColumn(); 
    var cellrow = mycell.getRow(); 

    //Define variables from sheet by column 
    //Column count starts at 0, not 1. 
    var timestamp = e.values[cellrow,14]; 
    var yourName = e.values[cellrow, 0]; 
    var email = e.values[cellrow, 1]; 
    var plot2013 = e.values[cellrow, 5]; 
    var plotrequest = e.values[cellrow, 6]; 
    var sharing = e.values[cellrow, 7]; 
    var totalprice = e.values[cellrow, 8]; 
    var paid = e.values[cellrow, 13]; 
    var subject = "TSF Payment Confirmation" 

    //email body 
    var emailBody = "Thank you for your payment submitted on " + timestamp + 
    "\n\nThe details you entered were as follows: " + 
    "\nYour name: " + yourName + 
    "\nYour plot #: " + plot2013 + 
    "\nNumber plots requested: " + plotrequest + 
    "\nSharing plot with: " + sharing + 
    "\nTotal payment: " + totalprice; 

    //html version of email body 
    var htmlBody = "Thank you for your payment submitted on <i>" + timestamp + 
    "</i><br/>&nbsp;<br/>The details you entered were as follows: " + 
    "<br/><font color=\"red\">Your Name:</font> " + yourName + 
    "<br/>Your Email: " + plot2013; 
    "<br/>Plots requested: " + plotrequest; 
    "<br/>Sharing plot with: " + sharing + 
    "<br/>Total payment: " + totalprice; 

    //sends email if cell contents are 'yes' 
    if (e.values[13,cellrow] == "yes") { 
    //Sends email 
    MailApp.sendEmail(email, subject, emailBody); 
    } 
} 

什麼我希望是,一旦用戶點擊在第13欄(假設從左側0的計數,而不是變量的數字)和類型「是」它將按照指定的來自該用戶行的信息發送電子郵件。

我收到一條錯誤信息,說:

VAR時間戳不確定

我認爲從這個例子在這裏:http://alamoxie.com/blog/tech-tips/sending-confirmation-emails-google-docs-form/

+0

爲什麼不與我們分享文檔? –

回答

0

你嘗試引用細胞的方式沒有意義(或工作)。試試這個測試/工作代碼,而不是:

function onEdit(e) { 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    var sheet = ss.getActiveSheet(); 

    // Ensure the event was triggered by typing "yes" in the appropriate column 
    if(e.range.getColumn() == 14 && e.value.toUpperCase() == "YES"){ 
    // Get the corresponding row 
    var row = sheet.getRange(e.range.getRow(), 1, 1, sheet.getLastColumn()).getValues()[0]; 

    // Define variable from row by column 
    var timestamp = row[14]; 
    var yourName = row[0]; 
    var email = row[1]; 
    var plot2013 = row[5]; 
    var plotrequest = row[6]; 
    var sharing = row[7]; 
    var totalprice = row[8]; 
    var paid = row[13]; 
    var subject = "TSF Payment Confirmation" 

    // Construct the email body 
    var emailBody = "Thank you for your payment submitted on " + timestamp + 
     "\n\nThe details you entered were as follows: " + 
     "\nYour name: " + yourName + 
     "\nYour plot #: " + plot2013 + 
     "\nNumber plots requested: " + plotrequest + 
     "\nSharing plot with: " + sharing + 
     "\nTotal payment: " + totalprice; 

    // Construct an HTML version of the email body 
    var htmlBody = "Thank you for your payment submitted on <i>" + timestamp + 
     "</i><br/>&nbsp;<br/>The details you entered were as follows: " + 
     "<br/><font color=\"red\">Your Name:</font> " + yourName + 
     "<br/>Your Email: " + plot2013; 
     "<br/>Plots requested: " + plotrequest; 
     "<br/>Sharing plot with: " + sharing + 
     "<br/>Total payment: " + totalprice; 

    // Send email 
    MailApp.sendEmail(email, subject, emailBody); 
    } 
} 

注意我把一切都放在一個條件語句;如果N列中的單元格未被更改爲「是」,則試圖解析所有數據是沒有意義的。緊接着,我從編輯的行中檢索所有值,並將結果填入所有變量。其餘的幾乎和你寫的一樣。

祝你好運!