在此代码中,我将为应用程序添加自定义大小?

时间:2017-05-04 10:00:23

标签: html google-apps-script google-sheets google-sheets-api

我在Google Scripts编辑器中创建了一个脚本,以便当用户点击Google表格中工具栏上的菜单时,会弹出一个用户点击打印的应用程序框。

但是,我不确定如何为该应用程序框添加自定义大小,而不会弄乱代码。

function onOpen() {
  SpreadsheetApp.getUi()
      .createMenu('Click to print')
      .addItem('Print from Google Cloud', 'openDialog')
      .addToUi();
}

function openDialog() {
var html = HtmlService.createHtmlOutputFromFile('Index')
    .setSandboxMode(HtmlService.SandboxMode.NATIVE);
    SpreadsheetApp.getUi()
    .showModalDialog(html, 'Click the button below to print using the Google Cloud Print service.');
}

index.html 代码为:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <script src="https://www.google.com/cloudprint/client/cpgadget.js">
</script>
<script>
  window.onload = function() {
    var gadget = new cloudprint.Gadget();
    gadget.setPrintButton(
        cloudprint.Gadget.createDefaultPrintButton("button"));
            var liabilityWaiver = waiver.getAs(MimeType.PDF);
    gadget.setPrintDocument("url", "Test Page", "https://drive.google.com/open?id=0B3NraNAa2RhWSldiNklPVGI5OU0");
  }
</script>
  </head>
  <body>
    <div id="button"></div>
  </body>
</html>

以下是脚本执行操作的图像说明:

enter image description here

enter image description here

enter image description here

enter image description here

正如您在上一张图片中所看到的那样,问题所在,应用程序框太小而无法容纳所有信息,因此将其删除。

- 编辑 -

我设法找到了如何在Matt的用户帮助下更大地创建应用程序框。但是,即使盒子更大,Google Cloud Print服务所在的窗口大小仍然很小,无论我在外部应用程序框中做多大。 (参见下面的图片以供参考。)

enter image description here

任何人都可以协助将内箱装到外箱的全尺寸吗?或者只是简单地把它变大?

最诚挚的问候。

1 个答案:

答案 0 :(得分:1)

查看https://developers.google.com/apps-script/reference/base/ui#showmodaldialoguserinterface-title

var htmlOutput = HtmlService
     .createHtmlOutput('<p>A change of speed, a change of style...</p>')
     .setWidth(250)
     .setHeight(300);
SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'My add-on');
相关问题