Google apps script 使用google脚本文件导出更改文档名称

Google apps script 使用google脚本文件导出更改文档名称,google-apps-script,Google Apps Script,我在一封电子邮件中以附件的形式发送了一份谷歌文档,虽然效果很好,但附件名为“export.docx”,我不知道如何更改它。我正在使用这个API- 我的代码如下。如果有人能帮我改变附加文件的名称,那将是伟大的!谢谢 function run(id, callback) { var service = getDriveService(); if (service.hasAccess()) { var token = service.getAccessToken(); var

我在一封电子邮件中以附件的形式发送了一份谷歌文档,虽然效果很好,但附件名为“export.docx”,我不知道如何更改它。我正在使用这个API-

我的代码如下。如果有人能帮我改变附加文件的名称,那将是伟大的!谢谢

function run(id, callback) {
  var service = getDriveService();
  if (service.hasAccess()) {
    var token = service.getAccessToken();
    var response = UrlFetchApp.fetch('https://www.googleapis.com/drive/v2/files/' + id + '/export?mimeType=application/vnd.openxmlformats-officedocument.wordprocessingml.document', {
      headers: {
        Authorization: 'Bearer ' + token
      }
    });
    MailApp.sendEmail({
      to: email,
      subject: "Attachments",
      htmlBody: "Please see attached.",
      attachments: [response]
    });
  } else {
    Logger.log("Access denied")
  }
}

执行此操作可重命名名称,如下所示:

function run(id, callback) {
  var service = getDriveService();
  if (service.hasAccess()) {
    var token = service.getAccessToken();
    var response = UrlFetchApp.fetch('https://www.googleapis.com/drive/v2/files/' + id + '/export?mimeType=application/vnd.openxmlformats-officedocument.wordprocessingml.document', {
      headers: {
        Authorization: 'Bearer ' + token
      }
    });
    MailApp.sendEmail({
      to: email,
      subject: "Attachments",
      htmlBody: "Please see attached.",
      attachments: [response.getBlob().setName("NewName")]  
    });
  } else {
    Logger.log("Access denied")
  }
}
基本上,使用setName函数将响应转换为要使用的blob和setnewName

希望有帮助