【问题标题】:Block a cell from being edited based on the value in another cell in Google spreadsheet根据 Google 电子表格中另一个单元格中的值阻止单元格被编辑
【发布时间】:2015-03-13 11:23:29
【问题描述】:

我试图弄清楚如何根据我的 Google 电子表格中另一个相邻单元格中的值来阻止一个单元格。

在我的 Google 电子表格中,A 列和 B 列都有一个下拉列表。如果从 A 列的下拉列表中选择了特定项目,我希望单元格 B1 被锁定。

我遇到了一个类似的链接,但我不知道如何调整它以满足我的需要。这是可以做到的吗?

【问题讨论】:

  • 您可以使用一个简单的onEdit() 触发器,它监视A 列中单元格的状态,然后作用于B1 单元格。 Google Documentation

标签: google-apps-script google-sheets


【解决方案1】:

要监控某个单元的状态,您可以使用简单的或可安装的触发器。一个简单的触发器只需要某个函数名,不需要其他设置。

function onEdit(e){
  // Get what range was edited
  var range = e.range;

  //Check the range address
  if (range === "A1") { //If range edited was the cell A1, then do something
    //Get the value in the edited cell
    var valueInCell = e.value;

    //Run a condition check
    if (valueInCell === edit Value Here) {
     //Get reference to cell to act upon

      //To Do: code here

    //Do something to cell

      //To Do: code here
    };
  };
};

【讨论】:

  • “谢谢!”,我真的很感谢这个答案,但坦率地说,我对脚本完全陌生,对此并不了解,所以请你给我一个示例脚本回答?
  • 您需要花一些时间学习 JavaScript 和 Google 方法,或者聘请一名程序员。
猜你喜欢
  • 2011-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多