在 Google 电子表格中,我创建了一个新菜单,用于打开一个对话框和一个边栏。我希望能够从侧边栏打开对话框

In Google Shreadsheet I have a created a new menu which opens a dialog and a sidebar. I want to be able to open the dialog from the sidebar

边栏是 html。 我想我可以 link 一个按钮到最初从菜单打开对话框的功能,但运气不好......什么也没做。想知道这是否可能是因为函数调用现在位于 html 文件中而不是实际电子表格中?也许?

这是侧边栏的代码:

<input type="button" value="New Booking" onclick="newContact()" ><p>
<script>
function newContact() {
var html = HtmlService.createHtmlOutputFromFile('Experimental')
  .setSandboxMode(HtmlService.SandboxMode.IFRAME)
  .setWidth(1050);
  //.setHeight(800);
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
  .showModalDialog(html, 'New Contact');}
</script>

HtmlService 代码需要来自 google 脚本 (.gs) 文件的 运行。它不会在标准 javascript 中工作,因为你已经在你的问题中设置了它。从 html 和 javascript,您可以 运行 .gs 函数与 google.script.run.newContact()。当然,您可以将 newContact 替换为您想要 运行.

的任何 .gs 函数

.gs码

 function sideBar(){
  var html = HtmlService.createHtmlOutputFromFile('index')
  .setSandboxMode(HtmlService.SandboxMode.IFRAME)
      .setTitle('My custom sidebar')
      .setWidth(300);
  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
      .showSidebar(html);
}
  function newContact() {
var html = HtmlService.createHtmlOutputFromFile('New Contact')
  .setSandboxMode(HtmlService.SandboxMode.IFRAME)
  .setWidth(1050);
  //.setHeight(800);
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
  .showModalDialog(html, 'New Contact');
  }

Index.html

<div>
<input type="button" value="New Booking" onclick="google.script.run.newContact()" ><p>
</div>

新建Contact.html

<div style="width:50px; height:50px; color:red;">
</div>