Alb*_*tus 5 ms-word google-api google-apps-script google-drive-api
是否可以使用Google Script以编程方式将Google文档转换为Word docx文件?
这应该工作
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);
}
Run Code Online (Sandbox Code Playgroud)
引用问题跟踪器上的此项目...
您现在可以使用 Drive Advanced Service 将 Google 文档转换为 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();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3267 次 |
最近记录: |