繁体   English   中英

从 Google Docs 获取 email

[英]Get email from Google Docs

我实际上想每天发送 MoM,所以我创建了一个文件夹,其中放置了所有 MoM 文档,并以创建日期为它们命名。 然后脚本在当天读取它并将其发送到固定的 email 地址,但现在我们将参与者插入到谷歌文档中,如下所示:- 在此处输入图像描述

有什么办法可以得到那里提到的那些 email 地址/用户 email 地址。

我之前使用的脚本是这样的:-

function sendMinutes() {
    const folder = DriveApp.getFolderById('Filder id')
    const today = Utilities.formatDate(new Date(),Session.getScriptTimeZone(),'MMM dd,yyyy')
    const files = folder.searchFiles(`title contains '${today}'`)
    while(files.hasNext())
    {
       let file= files.next()
       let doc = DocumentApp.openById(file.getId())
       let body = doc.getBody()
       let parag = body.getParagraphs().forEach(r=> {
          .....
       })
    }
}

我知道如何获取 email 但是,它现在只是返回第一个 email,我需要将每个 email 地址作为 ElementType 作为 PERSON:-

body.findElement(DocumentApp.ElementType.PERSON).getElement().asPerson().getEmail()

谢谢

Body.findElement有几个forms,其中一个使用两个参数,第二个是寻找下一个元素的起点。 将此方法表单与循环一起使用。 在以下示例中,使用了while语句:

function logEmailsFromPersonChips() {
  const doc = DocumentApp.getActiveDocument();
  const body = doc.getBody();
  let found;
  const emails = [];
  while ( found = body.findElement(DocumentApp.ElementType.PERSON,found)){
    const email = found.getElement().asPerson().getEmail();
    emails.push(email);
  }
  console.log(JSON.stringify(emails))
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM