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

大憨熊 提交于 2021-01-27 14:12:42

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/28041946/set-height-of-google-apps-script-showmodaldialog-when-using-an-htmlservice-htmlt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!