javascript - (javascript) 如何从单个单元格指向列中的所有单元格
问题描述
我有这个简单的代码,当有人从下拉菜单(数据验证)中选择名称时要求输入密码我的问题是它只将它定向到单个单元格,我应该添加或做什么以使其指向列中的所有单元格? 请看下文。
// define each user password
const userPasswords = {
"Guilherme Cudessuata": "123",
"Manuel Jose": "456",
"Emaculada": "789",
"Jonata Kedia": "111"
}
function onEdit(e) {
const namesCell = "E4" // the cell with the dropdown
if (e.range.getA1Notation() != namesCell) {
return
}
// show prompt for password:
var ui = SpreadsheetApp.getUi()
const response = ui.prompt("Password protected range",
"Please enter your password:",
ui.ButtonSet.OK_CANCEL)
const button = response.getSelectedButton()
const text = response.getResponseText()
// don't run if the user pressed cancel or close
if (button != ui.Button.OK) {
return
}
// check the passwords
if (text != userPasswords[e.value]) {
ui.alert('Incorrect Password', 'Please try again', ui.ButtonSet.OK);
e.range.setValue(e.oldValue) // reset to old value
}
}
解决方案
尝试这样的事情:
function onEdit(e) {
const sheetName = "Sheet1" //change to suit
const namesColumn = 5 // the column with the dropdown
const startRow = 4 //change to suit
const endRow = 100 //change to suit
if (e.range.getSheet().getName() != sheetName || e.range.columnStart != namesColumn || e.range.rowStart < startRow ||
e.range.rowEnd > endRow) {
return;
}
//rest of your code
}
...看看这是否有帮助?
参考:
推荐阅读
- latex - pandoc "titleformat" 标尺
- r - 在 ggplot2 中使用 facet_wrap 时通过两个轴上的相同值跟踪线性线
- python - 如何在 Matplotlib 和 Pandas 中绘制带有日期时间的阴影区域?
- swift - SKScene 类中的函数未运行
- c# - 跨线程操作无效:控件“lblStatus”从创建它的线程以外的线程访问
- python - 如何为networkx边缘添加权重?
- javascript - 使用 webpack 进行绘图
- javascript - 如何将输入数据从一个类传递到另一个类
- html - Spring 控制器映射到给定地址下的任何内容
- python - KeyError X:K-Means 聚类