2013-03-26 126 views

回答

0

this item的问题跟踪引用...

你可以转换一个谷歌文档今天DOCX使用驱动 先进型服务:

https://developers.google.com/apps-script/advanced/drive

这里是一个小例子:

function convertToDocx(documentId) { 
    var file = Drive.Files.get(documentId); 
    var url = file.exportLinks['application/vnd.openxmlformats-officedocument.wordprocessingml.document']; 
    var oauthToken = ScriptApp.getOAuthToken(); 
    var response = UrlFetchApp.fetch(url, { 
    headers: { 
     'Authorization': 'Bearer ' + oauthToken 
    } 
    }); 
    return response.getBlob(); 
} 
+0

你给用'documentId'一个代码示例 - 它(documentId)是指* documentId *在驱动器或文件?如何区分?如果我想保存到docx当前文档中,则应该如何保存到Google Doc脚本中: 'DocumentApp.getActiveDocument()...' – 2015-04-02 15:17:43

+0

不知道。没有尝试过自己的代码。 – Daniel 2015-04-02 23:25:56

+0

答案是:var documentId = DocumentApp.getActiveDocument()。getId();' – 2015-04-03 07:56:18

0

这应该工作

function myFunction() { 

    var token = ScriptApp.getOAuthToken(); 

    //Make sure to replace the correct file Id 
    // Fetch the docx blob 
    var blb = UrlFetchApp.fetch('https://docs.google.com/feeds/download/documents/export/Export?id=<ID_of_Google_Document>&exportFormat=docx', 
           { 
           headers : { 
            Authorization : 'Bearer '+token 
           } 
           }).getBlob(); 

    //Create file in Google Drive 
    var file = DriveApp.createFile(blb).setName('<name_of_exported_file>.docx'); 

    //Put the file in a drive folder 
    DriveApp.getFolderById('<FOLDER_ID>').addFile(file); 

} 
相关问题