html弹出窗口google.script.run适用于我,但不适用于制作工作簿副本的其他人

html弹出窗口google.script.run适用于我,但不适用于制作工作簿副本的其他人,html,google-apps-script,google-sheets,dialog,modeless,Html,Google Apps Script,Google Sheets,Dialog,Modeless,我有一个菜单项,加载一个无模式对话框,该对话框调用一个html文件,要求用户单击单元格,然后单击“确定”。一旦用户单击ok,它应该使用google.script.run在我的code.gs文件中运行一个函数。当我在我的帐户上执行此操作时,一切都可以无缝工作,但是当用户复制工作簿并尝试执行此操作时,会打开无模式对话框,但当他们单击“确定”时,google.script.run部分不工作。“确定”按钮看起来像是被点击了,对话框没有关闭,其他什么都没有发生 HTML文件 <!DOCTYP

我有一个菜单项,加载一个无模式对话框,该对话框调用一个html文件,要求用户单击单元格,然后单击“确定”。一旦用户单击ok,它应该使用google.script.run在我的code.gs文件中运行一个函数。当我在我的帐户上执行此操作时,一切都可以无缝工作,但是当用户复制工作簿并尝试执行此操作时,会打开无模式对话框,但当他们单击“确定”时,google.script.run部分不工作。“确定”按钮看起来像是被点击了,对话框没有关闭,其他什么都没有发生

HTML文件

    <!DOCTYPE html>
<html>
 <head>
  <!-- Current Version 5.8.21 -->
   <base target="_top">
 </head>
 <body>
   <p>Select Cell for New Step, then Click OK."</p>
   <input type="button" class="button" value="OK" onclick="google.script.run.znewStep();">
 </body>
</html>

正如我所说的,一切对我来说都很好,但是当工作簿被其他人复制时,它就不起作用了。

此脚本将单元格选择和值输入组合在一起,所有这些都组合在html无模式对话框中。因此,您不再需要模态提示

一般事务:

如果以这种方式运行,那么您甚至不需要模式提示,他们只需在html对话框中输入数据,然后按ok

function znewStep(newStep) {
  try {
    var spreadsheet = SpreadsheetApp.getActive();
    spreadsheet.getCurrentCell().offset(0, 0).activate();
    spreadsheet.getCurrentCell().offset(-1, 0, 5, 2).copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
    spreadsheet.getCurrentCell().offset(0, 0).activate();
    spreadsheet.getCurrentCell().setValue(newStep);
    spreadsheet.getCurrentCell().offset(1, 0).activate();
    showMyDialog();
  }
  catch (e) {
    SpreadsheetApp.getUi().alert(e);//alerts users to picking too small of a row number 
  }
};


function showMyDialog() {
  SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutputFromFile('ah1'),'Step');//ah1.html is the name of the file I am using
}
HTML:


为新步骤选择单元格并输入值,然后单击“确定”

函数getNewStep(){ 设v=document.getElementById('txt1').value; google.script.run.znewStep(v);//立即将新值发送到znewStep函数 google.script.host.close(); }

但看起来您甚至不需要该对话框。

欢迎使用。请在执行页面或web浏览器控制台上添加文本错误消息。感谢您回复鲁本。当我检查执行日志时,它只显示showStepDialog已完成(这是打开无模式对话框的功能),但当我单击“确定”时,执行日志上根本没有任何内容。没有执行对话框的脚本。您查看过web浏览器控制台吗?(这是web浏览器开发人员工具之一)与您共享该工具的人是否进入脚本编辑器并授权脚本?对话框将打开一个弹出窗口,提示用户选择一个单元格,以便在其中添加新步骤。然后,当他们单击“确定”时,将打开一个弹出窗口,询问步骤应该是什么,然后将新步骤插入所选单元格,并向下移动所有其他单元格。在我自己的工作簿中可以完美地工作,但当别人复制时,它对他们不起作用。这是我见过的最奇怪的事情。你是如何给他们代码的?与你共享代码的人是否进入脚本编辑器并授权了脚本?它绑定到电子表格,他们也授权了脚本(我还尝试了我的另一个谷歌账户,但没有成功)。其他所有功能都可以正常工作。似乎两个运行google.script.run.function的html文件都不起作用。他们可以打开并查看所有代码。我想知道这是否与启用弹出窗口有关?
function znewStep(newStep) {
  try {
    var spreadsheet = SpreadsheetApp.getActive();
    spreadsheet.getCurrentCell().offset(0, 0).activate();
    spreadsheet.getCurrentCell().offset(-1, 0, 5, 2).copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
    spreadsheet.getCurrentCell().offset(0, 0).activate();
    spreadsheet.getCurrentCell().setValue(newStep);
    spreadsheet.getCurrentCell().offset(1, 0).activate();
    showMyDialog();
  }
  catch (e) {
    SpreadsheetApp.getUi().alert(e);//alerts users to picking too small of a row number 
  }
};


function showMyDialog() {
  SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutputFromFile('ah1'),'Step');//ah1.html is the name of the file I am using
}
<!DOCTYPE html>
<html>
<head>
    <base target="_top">
</head>
<body>
  <p>Select Cell for New Step and enter value then Click OK.</p>
  <input type="text" id="txt1"/>
  <input type="button" class="button" value="OK" onclick="getNewStep();">
  <script>
    function getNewStep() {
      let v = document.getElementById('txt1').value;
      google.script.run.znewStep(v);//send the new value to the znewStep function now
      google.script.host.close();
    }
  </script>
</body>
</html>