2
votes

Does anyone has experience in convert a batch of .docx file, stored in Google Drive, to Google Doc format?

I read the solution posted 3 years ago by Youssef, but it is not working anymore.

Docx to Google Doc using Google Script

When I try to replicate his solution below, I have this error message: We're sorry, a server error occurred. Please wait a bit and try again.

var docx = DriveApp.getFileById("###");

var newDoc = Drive.newFile();
var blob =docx.getBlob();
var file=Drive.Files.insert(newDoc,blob,{convert:true});

The code stops in docx.getBlob()

I will really appreciate your support!!

1

1 Answers

4
votes

This function uses some of the advanced Drive APIs and as such, require you to enable them from the script editor first, before running the script. To achieve this, go to:

Resources > Advanced Google Services... > Scroll all the way down to Drive API > toggle the off button to on

Advanced resources

Here's the final script -

function myFunction() {
  var docx = DriveApp.getFilesByName('Dummy.docx').next();
  var newDoc = Drive.newFile();
  var blob =docx.getBlob();
  var file=Drive.Files.insert(newDoc,blob,{convert:true});
  DocumentApp.openById(file.id).setName(docx.getName());  
}

Hope this helps!