如何获取文件 ID 以从 GoogleSheets/Script 发送邮件

How to get file ID to send mails from GoogleSheets/Script

我是编码新手,我遇到了代码问题,在参数

之后我不断收到 “错误语法:缺少 )”

这是我当前的代码:

    function myFunction(){
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet('Form Responses 1');
  const url = sheet.getRange().getValues();
  url.forEach(function(row,index){
    if (index === 0) return;
    if (row[19]) return;
  const idFile = url.match(/[-w]{25,}/);
  const file = DriveApp.getFileById(idFile)
  const blob = file.getAs(MimeType.PDF)

  var message = 'Thanks for your interest this will be the first step'
  var mail = row[2]
  var team = row[8]
GmailApp.sendEmail(mail,team,"Subject",message,{attachments: [blob]})

这是我的第二个脚本,我构建的第一个脚本是为每个新的 google 表单条目创建 PDF,在第 19 列中写入了 PDF link。这个想法是,在创建 PDF linked 之后,它会获取文件 ID,然后自动将其发送给填写表格并抄送给我的团队的人,如果没有创建 link,那么它应该不发送。

但我已经研究过,老实说我不太了解如何识别我的错误,我希望任何人都可以帮助我,我将不胜感激。 要么不提供答案,而是以任何形式提供帮助,我们将不胜感激!

箭头函数后缺少括号,请参阅下面的评论

function myFunction() {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet('Form Responses 1');
  const url = sheet.getRange().getValues();
  url.forEach(function (row, index) {
    if (index === 0) return;
    if (row[19]) return;
    const idFile = url.match(/[-w]{25,}/);
    const file = DriveApp.getFileById(idFile)
    const blob = file.getAs(MimeType.PDF)

    var message = 'Thanks for your interest this will be the first step'
    var mail = row[2]
    var team = row[8]
    GmailApp.sendEmail(mail, team, "Subject", message, { attachments: [blob] })
  });//your missing the parenthesis here after the arrow function
 }

您缺少几个右括号和圆括号。

function myFunction(){
    const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet('Form Responses 1');
    const url = sheet.getRange().getValues();
    url.forEach(function(row,index){
        if (index === 0) return;
        if (row[19]) return;
        const idFile = url.match(/[-w]{25,}/);
        const file = DriveApp.getFileById(idFile);
        const blob = file.getAs(MimeType.PDF);

        var message = 'Thanks for your interest this will be the first step';
        var mail = row[2];
        var team = row[8];
        GmailApp.sendEmail(mail,team,"Subject",message,{attachments: [blob]});
    });
}