2013-03-26 65 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); 

}