How can I generate a multipage text document from a single page template in google-apps-script?

Well Serge, haven’t you tried the appendParagraph and other appends of the DocumentBodySection? I’d do it like this: function mergeDocs() { var docIDs = [‘list-of’,’documents’,’ids’,’you should have somehow’]; var baseDoc = DocumentApp.openById(docIDs[0]); var body = baseDoc.getActiveSection(); for( var i = 1; i < docIDs.length; ++i ) { var otherBody = DocumentApp.openById(docIDs[i]).getActiveSection(); var totalElements = otherBody.getNumChildren(); … Read more

How to define global variable in Google Apps Script

You might be better off using the Properties Service as you can use these as a kind of persistent global variable. click ‘file > project properties > project properties’ to set a key value, or you can use PropertiesService.getScriptProperties().setProperty(‘mykey’, ‘myvalue’); The data can be retrieved with var myvalue = PropertiesService.getScriptProperties().getProperty(‘mykey’);

Creating anchored comments programmatically in Google Docs

The Anchoring Comments feature from the Google Drive API is intended for non-Google Docs editors files, not for Google Documents. See https://youtu.be/ZBU52nacbLw?t=5m26s (credit to Bryan P who shared this URL through a comment) Unfortunatelly at this time the Document Service from Google Apps Script doesn’t include a Class Comment to handle comments and discussions. At … Read more

wget/curl large file from google drive

November 2021 You can use gdown. Consider also visiting that page for full instructions; this is just a summary and the source repo may have more up-to-date instructions. Instructions Install it with the following command: pip install gdown After that, you can download any file from Google Drive by running one of these commands: gdown … Read more

How to poll a Google Doc from an add-on

The polling is done from the html code in your add-on’s User Interface, calling across to server-side Apps Script functions using google.script.run. Using jQuery simplifies this, and we can even start with the answers from jQuery, simple polling example. function doPoll(){ $.post(‘ajax/test.html’, function(data) { alert(data); // process results here setTimeout(doPoll,5000); }); } The basic idea … Read more