如果您获得作为数组返回的数据,您可以使用 JavaScript indexOf() 方法检查现有值。
- 从电子表格中获取数据
- 使用要写入的值检查现有值
- 如果存在价值,请通知您。
获取数据
Google Documentation - Get Values
// The code below will get the values for the range C2:G8
// in the active spreadsheet. Note that this will be a javascript array.
var values = SpreadsheetApp.getActiveSheet().getRange(2, 3, 6, 4).getValues();
Logger.log(values[0][0]);
检查重复:
var returnFromIndexOf = values.indexOf(valueToChk);
通知您:
if (values.indexOf(valueToChk) != -1) {
//Send me an email
// Send an email with two attachments: a file from Google Drive (as a PDF) and an HTML file.
var file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz');
var blob = Utilities.newBlob('Insert any HTML content here', 'text/html', 'my_document.html');
MailApp.sendEmail('mike@example.com', 'Attachment example', 'Two files are attached.', {
name: 'Automatic Emailer Script',
attachments: [file.getAs(MimeType.PDF), blob]
});
};
Google Documentation - Send Email
您需要将 Google 表单安装到您的 Google 云端硬盘才能创建新表单。
Google Site - Google Forms
有一些方法可以在提交表单时运行一些代码。您可以在提交表单时从电子表格或附加到电子表格的表单中运行事件。
在 Apps 脚本代码编辑器中,打开 资源 菜单并添加触发器以在提交表单时运行函数。