这是一个由两部分组成的问题:
- 我有带有链接表单的 Google 表格。提交表单后,我希望将表单中的响应复制到另一个谷歌表格中,我打算在其中进行更改和重新格式化,然后通过电子邮件发送。下面的脚本是我当前编写的,它在FormSubmit 上设置了一个触发器。但是,我不断收到以下错误:
类型错误:无法从未定义中读取属性“值”。 (第 7 行,文件“代码”)
代码如下:
function formSubmitReply(e)
{
var t = "1g-wIs6nGxu3mJYA1vKtPCxBLCsvh1upeVGbCokOOTIw";
var tName = "AggregationOutput";
//Get information from form and set as variables
var email = e.Values[2];
var name = e.Values[3];
// Get template, copy it as a new temp, and save the Doc’s id
var tcopyId = SpreadsheetApp.openById(t).copy(tName+' for '+name).getId();
// Open the temporary document & copy form responses into template copy response sheet
var copyt = SpreadsheetApp.openById (tcopyId);
var copyts = copyt.getSheetByName('Resp');
// Transfers Data from Form Responses to Temporary file
copyts.getRange('A3').setValue(name);
//Sends copy of template in an email as an excel file
var url = "https://docs.google.com/feeds/download/spreadsheets/Export?key=" + copyt.getId();
var subject = 'Aggregaton Output for' + name;
var body = url
MailApp.sendEmail(email, subject, body);
// Deletes temp file
DriveApp.getFileById(tcopyId).setTrashed(true);
}
- 我的问题的第二部分,即使我可以让代码工作,当在表单中跳过问题时,您会建议什么 - 这不会改变 e.values 中的数组吗?使用最后一行作为问题是我希望人们返回并编辑表单上的响应,然后重新提交,这意味着最后一行并不总是使用的行。
感谢任何和所有帮助。
最佳答案
对于第 1 部分,请尝试以下操作:
function formSubmitReply(e)
{
var t = "1g-wIs6nGxu3mJYA1vKtPCxBLCsvh1upeVGbCokOOTIw";
var tName = "AggregationOutput";
//Get information from form and set as variables
var itemResponses = e.response.getItemResponses();
var email = itemResponses[2].getResponse();
var name = itemResponses[3].getResponse();
// Get template, copy it as a new temp, and save the Doc’s id
var tcopyId = SpreadsheetApp.openById(t).copy(tName+' for '+name).getId();
// Open the temporary document & copy form responses into template copy response sheet
var copyt = SpreadsheetApp.openById (tcopyId);
var copyts = copyt.getSheetByName('Resp');
// Transfers Data from Form Responses to Temporary file
copyts.getRange('A3').setValue(name);
//Sends copy of template in an email as an excel file
var url = "https://docs.google.com/feeds/download/spreadsheets/Export?key=" + copyt.getId();
var subject = 'Aggregaton Output for' + name;
var body = url
MailApp.sendEmail(email, subject, body);
// Deletes temp file
DriveApp.getFileById(tcopyId).setTrashed(true);
}
关于javascript - 当尝试在 Google Sheet 脚本中使用 e.value 时,我得到 TypeError : Cannot read property "Values" from undefined. (第 7 行,文件 "Code"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42082032/