2017-04-09 61 views
0

我發送一個谷歌文檔作爲附件在一個電子郵件工作正常,但附件被稱爲'export.docx',我不知道如何改變它。我正在使用這個API - https://developers.google.com/drive/v2/reference/files/export更改文檔的名稱使用谷歌腳本文件導出

我的代碼如下。如果有人可以幫助我改變附件的名字,那就太棒了!謝謝!

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") 
    } 
} 

回答

1

這樣做可以重命名的名稱,像這樣:

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") 
    } 
} 

基本上,轉換成BLOB和使用setnewName響應,使用的setName功能

希望幫助