我有一个菜单项,它加载一个无模式对话框,该对话框调用一个 html 文件,该文件要求用户单击一个单元格,然后单击确定。一旦用户单击确定,它应该使用 google.script.run 在我的 code.gs 文件中运行一个函数。当我在我的帐户上执行此操作时,一切都可以无缝运行,但是当用户复制工作簿并尝试执行此操作时,会打开无模式对话框,但是当他们单击确定时,google.script.run 部分不起作用。“确定”按钮看起来像是被点击了,对话框没有关闭,没有其他任何事情发生。
文件
<!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>
那么这是它正在调用的代码:
function znewStep() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getCurrentCell().offset(0, 0).activate();
spreadsheet.getCurrentCell().offset(-1, 0, 50, 2).copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
spreadsheet.getCurrentCell().offset(0, 0).activate();
var newStep = SpreadsheetApp.getUi().prompt("Please enter new step:").getResponseText();
spreadsheet.getCurrentCell().setValue(newStep);
spreadsheet.getCurrentCell().offset(1, 0).activate();
};
就像我说的一切对我来说都很好,但是当工作簿被其他人复制时,它就不起作用了。