Google表格-如果在复选框中打勾,请创建带有按钮的弹出消息

问题描述 投票:0回答:2

我是Google表格的新手。以前,我有一些C ++背景。

我想编写执行以下操作的自定义代码:

  1. 勾选复选框
  2. 确认信息弹出
  3. 是肯定的检查,不取消勾选框。

在C中,一个函数只能运行一次,然后退出。如何在Google工作表中编写代码,以便该代码不断检查复选框状态?

是否正在运行某种条件脚本?

google-apps-script google-sheets
2个回答
0
投票

您可以按照注释中的建议尝试使用OnEdit Trigger,然后选中复选框的值。使用信息here检查复选框的值,然后使用此代码的某些变体创建弹出对话框:

function showAlert() {
  var ui = SpreadsheetApp.getUi(); // Same variations.

  var result = ui.alert(
     'Please confirm',
     'Are you sure you want to continue?',
      ui.ButtonSet.YES_NO);

  // Process the user's response.
  if (result == ui.Button.YES) {
    // User clicked "Yes".
    ui.alert('Confirmation received.');
  } else {
    // User clicked "No" or X in the title bar.
    ui.alert('Permission denied.');
  }
}

0
投票
function onEdit(e) {
  const sh=e.range.getSheet();
  if(sh.getName()=='Sheet14' && e.range.columnStart==1 && e.value=='TRUE') {
    var resp=SpreadsheetApp.getUi().prompt('Title', 'Message', SpreadsheetApp.getUi().ButtonSet.YES_NO);
    if(resp.getSelectedButton()==SpreadsheetApp.getUi().Button.YES) {
      return;
    }else{
      e.range.setValue('FALSE');
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.