我試圖使我的Google表單每次有人填寫表單時都會通過電子郵件向我發送表單內容。我正在使用下面的說明,並且我完全遵循了它們。然而,出於某種原因,當我填寫表單時,出現「TypeError:Can not call method」getRange「爲空的錯誤(第7行,文件」代碼「)」Google表單腳本發送電子郵件故障
我看了代碼正上方,其中定義了「s」,我在想,問題在於getActiveSpreadsheet由於某種原因無法正常工作。我認爲腳本可能找不到活動工作表。根據我從google獲得的錯誤電子郵件,下面是導致問題的代碼片斷。
var s = SpreadsheetApp.getActiveSheet();
var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
我正在使用的整段代碼;
function sendFormByEmail(e)
{
// Remember to replace this email address with your own email address
var email = "[email protected]";
var s = SpreadsheetApp.getActiveSheet();
var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
var message = "";
var subject = "Jones IT - New User Form";
// The variable e holds all the form values in an array.
// Loop through the array and append values to the body.
for(var i in headers)
message += headers[i] + ': '+ e.namedValues[headers[i]].toString() + "\n\n";
// Insert variables from the spreadsheet into the subject.
// In this case, I wanted the new hire's name and start date as part of the
// email subject. These are the 3rd and 16th columns in my form.
// This creates an email subject like "New Hire: Jane Doe - starts 4/23/2013"
subject += e.namedValues[headers[1]].toString() + " - starts " + e.namedValues[headers[2]].toString();
// Send the email
MailApp.sendEmail(email, subject, message);
}
糟糕,第一次在這個網站上,我把我的評論作爲答案,我的壞。我還有一個問題,如果你要回答它,但它不適合在這個評論框中,所以我發佈它作爲答案。 – 2015-02-17 19:55:54