0

I have 800+ google sheets inside my google drive. I want to make these google sheets published to web using apps script and get the pubhtml link after.

The manual process of "publish to web" is go to file->publish to the web->publish. I want this to be automated using appscript. I appreciate your help on this.

  • Have you read [how to publish to the web a spreadsheet using drive API and GAS](https://stackoverflow.com/a/41743755/1330560)? – Tedinoz Nov 04 '19 at 08:13

1 Answers1

0

I will leave you this code, which can help you to publish automatically all those spreadsheets

function publishSheetsToWeb() {
 // Log the name of every file in the user's Drive.
 var files = DriveApp.getFiles();
 while (files.hasNext()) {
   var file = files.next();
   // Check if it is a spreadsheet
   if(file.getMimeType() === 'application/vnd.google-apps.spreadsheet'){
     try{
       var fileId = file.getId();
       // get the revisions and then get the last one of them
       var revisions = Drive.Revisions.list(fileId); 
       var lastRevisionId = revisions.items[revisions.items.length - 1].id;
       // get the resource and set the publish parameters
       var resource = Drive.Revisions.get(fileId, lastRevisionId);  
       resource.published = true;
       resource.publishAuto = true;
       resource.publishedOutsideDomain = true;
       // publish to the web
       Drive.Revisions.update(resource, fileId, lastRevisionId); 
     }  catch(err) {
       Logger.log(err); 
     }
   }
 }
}

Notice

  • To get the public URLs you can refer to this post

  • Because you are trying to make public a lot of docs, be careful with the quotas limits. You can learn more about them here

Community
  • 1
  • 1
alberto vielma
  • 2,302
  • 2
  • 8
  • 15