Google apps script Google表单响应表脚本,用于将模板电子表格的副本触发为新文件名
我创造了:Google apps script Google表单响应表脚本,用于将模板电子表格的副本触发为新文件名,google-apps-script,google-sheets,google-forms,Google Apps Script,Google Sheets,Google Forms,我创造了: Google Sheet作为我根驱动器中的主模板(“QC_MasterTemplate”),具有我想要的所有格式,以便为每个新的销售订单完成检查表 收集新客户姓名、id和订单接收日期的谷歌表单,我们的销售人员将使用该表单提交回复 谷歌表单链接到存储新订单响应的表单。我还有一个我的脚本,它运行在表单Submit上,该表单将新条目提交到此工作表,该表单收集最后一行条目信息 我需要帮助的是: 响应表中的脚本正在工作,以触发我的通知电子邮件,通知已创建新条目,并将每个单元格的详细信息分解为电
function createNewSheet() {
// Get Template Filename
var TemplateFile = DriveApp.getFilesByName("QC_MasterTemplate");
// Get current spreadsheet for information lookup
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Last row of data to process
var startRow = sheet.getLastRow();
// Starting Column of data to process
var startColumn = 1;
// Number of rows to process
var numRows = 1;
// Number of columns to process
var numColumns = sheet.getLastColumn();
// Get range of cells in columns A:E for all rows with entries
var dataRange = sheet.getRange(startRow, startColumn, numRows, numColumns)
// Get entries for each row in the Range.
var data = dataRange.getValues();
// Set each value to a unique variable
for (i in data) {
var cell = data[i];
var timestamp = cell[0];
var companyname = cell[1];
var customerid = cell[2];
var orderdate = cell[3];
var employee = cell[4];
// Build body of email
var subject = companyname + "-" + customerid + "-" + orderdate + " - QC Checklist";
var message = 'New QC Checklist Form Received \n' +
'\nTimestamp: ' + timestamp +
'\nCompany Name: ' + companyname +
'\nCompany ID: ' + customerid +
'\nOrder Date: ' + orderdate +
'\nEmployee Name: ' + employee;
var recipient = "username@gmail.com";
MailApp.sendEmail(recipient, subject, message);
// Make copy of Template to new filename
subject.makeCopy(TemplateFile);
}
}
我得到的错误是:
类型错误:在object-37188-20150401-QC检查表中找不到函数makeCopy。(第39行,文件“代码”)相反,您可以获取电子表格的父文件夹(QC_MasterTemplate),转到该文件夹并创建新的电子表格文件 为了获得电子表格的根文件夹(QC_MasterTemplate),您可以使用DriveApp中的方法
function makeCopyOfTemplate() {
var templateID = 'The File ID of the File'; //Template File ID
var workingCopy = DriveApp.getFileById(templateID).makeCopy();
var workingFileID = workingCopy.getId();
var fileNameToUse = 'CustomerABC Todays Date';
//Set the file name of the copy file
workingCopy.setName(fileNameToUse);
//Open the new copy of the Template
var workingCopyOfTemplateFile = SpreadsheetApp.openById(workingFileID);
//To Do: Inject copy with data
};
此外,创建电子表格时,必须使用方法
希望有帮助 名为
subject
的变量是一个字符串。没有从字符串生成文件的makeCopy()
方法。谷歌应用服务是面向对象的编程。你需要从顶部开始,然后逐步深入到方法。有一个makeCopy()
方法:
但你不能在任何事情上使用这种方法。对于该特定文档,makeCopy()
方法仅适用于文件类。因此,首先需要获取对文件的引用
可能有多种方法可以复制模板
一个选项是使用DriveApp类
function makeCopyOfTemplate() {
var templateID = 'The File ID of the File'; //Template File ID
var workingCopy = DriveApp.getFileById(templateID).makeCopy();
var workingFileID = workingCopy.getId();
var fileNameToUse = 'CustomerABC Todays Date';
//Set the file name of the copy file
workingCopy.setName(fileNameToUse);
//Open the new copy of the Template
var workingCopyOfTemplateFile = SpreadsheetApp.openById(workingFileID);
//To Do: Inject copy with data
};
也可以使用
.makeCopy(名称、目的地)
方法吗
var ss = SpreadsheetApp.getActiveSpreadsheet();
var lmName = (ss.getName() + "_2016-11");
var lmfoldername = ('2016-11-Update');
var lmFolder = DriveApp.getFoldersByName(lmfoldername).next();
DriveApp.getFileById(ss.getId()).makeCopy(lmName, lmFolder);
谢谢,这对我有帮助。我还意识到我的问题的一部分是没有正确指定“文件的文件ID”。