首页 > 解决方案 > Google 表格插件侧边栏点击事件不适用于某些用户

问题描述

谷歌表格附加边栏问题

单击侧边栏中的菜单项时,不会触发 Code.gs 中的应用脚本功能。google.script.run.withSuccessHandler().withFailureHandler().generateContract();---> 不适用于某些用户。

代码.gs

function onOpen() {
  SpreadsheetApp.getUi().createAddonMenu().addItem('Sidebar', 
  'showSidebar').addToUi();  
}

function generateContract() {
  var ui = SpreadsheetApp.getUi();
  ui.alert("Hello there! You're in the generateContract Function.");
  return;
}

function showSidebar() {  
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Data");  
  var ui = SpreadsheetApp.getUi();
  var emailID = Session.getEffectiveUser().getEmail();
    var html= HtmlService.createHtmlOutputFromFile('sidebar').setTitle("Sidebar");
  ui.showSidebar(html);
  
}

警报“您好!您在 generateContract 函数中。” 某些用户不会被解雇。不知道为什么。

边栏.html

<!DOCTYPE html>
<html>
<head>
    <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@200;300;400;500;600;700&display=swap" rel="stylesheet">  
    <base target="_top">
    <script>
        function generatecontracts() {
            document.getElementById("generate-contracts").classList.toggle("show");
        }

        function GenerateContract() {
            google.script.run.withSuccessHandler().withFailureHandler().generateContract();
        }
    </script>
</head>
<body style="margin: 0px; overflow: hidden">
    <div class="dropdown">
        <div class="d-flex">
            <button onclick=generatecontracts() class="dropbtn db-txt">
                Generate Contracts
            </button>
            <button onclick=generatecontracts() class="arrow">&#x25BC;</button>
        </div>
        <div class="dropdown-content" id="generate-contracts">
            <button class="drop-btn" onClick='GenerateContract()'>Generate Contract</button>
        </div>
    </div>
</body>
</html>

标签: google-apps-scriptgoogle-sheetsadd-on

解决方案


推荐阅读