Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set height of Google Apps Script showModalDialog when using an HtmlService HtmlTemplate

I'm currently in the process of changing over my Google Apps Scripts that use the deprecated UI service to the HtmlService.

I've created a modal dialogue using the following code (in a spreadsheet container-bound script):

var htmlTemplate = HtmlService.createTemplateFromFile('testDialogue');

htmlTemplate = template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);

SpreadsheetApp.getUi().showModalDialog(htmlTemplate, 'Test Dialogue');

The dialogue box opens, but I need to modify its dimensions.

HtmlOutput objects have a setHeight method, but there doesn't seem to be the same method available for HtmlTemplate objects.

I tried using the method anyway on the object like this:

var htmlTemplate = HtmlService.createTemplateFromFile('testDialogue').setHeight(300);

But that produces this error:

TypeError: Cannot find function setHeight in object HtmlTemplate

Also, I checked the SpreadsheetApp Ui Class and showModalDialog method but neither of them seem to have methods for setting the height of HtmlTemplate objects.

like image 388
Employee Avatar asked Mar 18 '23 07:03

Employee


1 Answers

The .setHeight() method can be used when chaining it after the .evaulate() method, like so:

template = template.evaluate()
                   .setSandboxMode(HtmlService.SandboxMode.IFRAME)
                   .setHeight(300);

Update 2/19/19: The .setSandboxMode() method no longer has any effect - now all scripts now use IFRAME mode regardless of what sandbox mode is set (documentation). That method was not related to setting the height but I figured I'd mention this in case anyone ends up copying and pasting this code sample.

like image 72
Employee Avatar answered May 01 '23 08:05

Employee