I was working on a Google Apps Script project lately in Google Sheets that set up parameters in a sidebar and then ran the process once the user clicked the “Submit” button. The problem was that the process was taking a while and that “Submit” Button was ripe to be clicked multiple times by the impatient user, before the server-side code could even finish it’s operation.
To fix this I needed to disable the submit button once it had been clicked and then enable it again once the server-side process was complete. Here, I need to:
- Do something awesome with it server-side.
- Upon the completion of the server-side awesome, call back to the html file and enable the button again.
I have a very simple Google Sheets Side Bar with a “Submit” and “Cancel” button. When the “Submit” button is clicked it calls the function
submittington (can he get any more creative? No. No he can’t).
This function then disables the “Submit” button sends a variable to the client side code.gs and displays it stylishly in the sheet multiple times for the users viewing pleasure. After the code.gs function is executed, it calls back to the client-side
submittington function and enables the button.
Behold!!! The example:
Continue reading “Google Apps Script – Disable Enable Submit Button in Sidebar”
*.gs and Html files
Then, what’s the trick?
Instead, we will need to use the templating method:
html = HtmlService.createTemplateFromFile(filename)
We will get into a little more detail on templates later in this tutorial.
My main reference for this was the Google Apps Script UI best practice guide, and you will see code snippets of the first example there that I have modified for my own example.
The thing is, the explanations were a bit vague for me to work out clearly so I really needed to create an example of my own to work through how to use it. The example below breaks down the steps to create file relationships to make your code look neater. It also dives into some uses of template statements in html.
The Final Result
Take a look at the demo:
Sometimes you need to prepare a Google Doc’s paper size and orientation programatically using Google Apps Script.
Unfortunately, you can’t just call for say, A4 in Landscape. Okay, not until now (see my code below).
Google Apps Script does provide a way to set the dimensions of your page in the body class by using:
The page widths and heights are measured in PostScripts Points which is a bit of a pain too.
Here is an example of setting and A3 paper size in Landscape.
var document = DocumentApp.getActiveDocument();
Ugh. What a chore. You need to find the dimensions of the paper in points.
Enter this little nifty function and your life will be so much easier:
Continue reading “Set the Paper Size and Orientation in a Doc Using Google Apps Script”