【发布时间】:2014-04-29 15:04:33
【问题描述】:
我目前正在使用以下方式向分发列表发送一封电子邮件,其中包含提交 Google 表单时的标题/问题和相应答案:
function sendFormByEmail(e) {
// Subject field of email
var emailSubject = "New Student Case Filed";
// Comma-separated list of email addresses for distribution.
var yourEmail = "my email address";
// Spreadsheet key, found in the URL when viewing your spreadsheet.
var docKey = "my spreadsheet key";
// If you want the script to auto send to all of the spreadsheet's editors, set this value as 1.
// Otherwise set to 0 and it will send to the yourEmail values.
var useEditors = 0;
// Have you added columns that are not being used in your form? If so, set this value to
// the NUMBER of the last column that is used in your form.
// for example, Column C is the number 3
var extraColumns = 40;
if (useEditors) {
var editors = DocsList.getFileById(docKey).getEditors();
if (editors) {
var notify = editors.join(',');
} else var notify = yourEmail;
} else {
var notify = yourEmail;
}
// The variable e holds all the submission values in an array.
// Loop through the array and append values to the body.
// Need to omit headers with no response*
var s = SpreadsheetApp.getActive().getSheetByName("StudentCases");
if (extraColumns){
var headers = s.getRange(1,1,1,extraColumns).getValues()[0];
} else var headers = s.getRange(1,1,1,40).getValues()[0];
var message = "";
for(var i in headers) {
message += headers[i] + ' : '+ e.values[i].toString() + '\n\n';
}
现在我还想要创建一个包含标题和响应的 Google 文档。到目前为止,我已经能够创建 Doc、添加标题和添加段落,但现在我还需要在 Google Doc 中复制标题/响应数组。
// Create a new Google Doc named 'Case File' * need to figure out how to pull last name response from form.
var doc = DocumentApp.create('Case File: Last Name*');
// Access the body of the Doc, add a paragraph, *need to append array of headers/answers
var body = doc.getBody().body.appendParagraph();
// Get the URL of the Google Doc to include in Email
var url = doc.getUrl();
// Get ID of Doc to attach to email
var id = doc.getId()
我想解决的另一个问题;我只需要包含响应的标题/问题,因为其中许多不一定保证答案。所以换句话说,如果没有答案,那么不要附加到电子邮件中。
【问题讨论】:
-
StackOverflow 面向简单的技术问题和答案。如果您正在寻找更全面的帮助,您应该考虑在 Apps Script Google+ 社区之一发帖:plus.google.com/s/%22Apps%20Script%22/communities
标签: google-apps-script google-docs google-forms