google-apps-script - how do I get the onEdit function to run
问题描述
I am making my own D&D sheet for my friends. I would like this to be as cool and as complex as possible. Currently the onEdit function isn't even triggering . I am trying to hide certain rows based on J3, if J3 = 1 then row 7 will be hidden. In the future I will hide rows 7-10, if J3 >= 2 then it will show rows 7-10. When it changes nothing happens. Please help.
function onEdit() {
var sheet = SpreadsheetApp.getActive().getSheetByName('Actions')
var status = sheet.getRange('J3').getValue();
if (status == 1) {
sheet.hideRows(7);
} else {
if (status >= 2) {
sheet.showRows(7);
}
}
Logger.log('yay you did it')}
解决方案
这对我有用:
function onEdit(e) {
var sh=e.range.getSheet()
if(sh.getName()!='Actions')return;
var status=sh.getRange('J3').getValue();
if (status==1) {
sh.hideRows(7);
}else if(status>=2){
sh.showRows(7);
}
}
推荐阅读
- python - 使用 ipywidgets FileUpload 小部件时,我可以定义文件上传操作吗
- c# - 使用 linq 查询为每一行获取重复的行
- python - 问题从套接字接收图像数据到 pygame
- mxnet - CUDA忽略错误,检查失败:e == cudaSuccess:CUDA:初始化错误
- numpy - Numpy数组 - 像素坐标
- javascript - 如何正确迭代 API 密钥数组以同步发出请求?
- python - 如何将5分钟的降雨记录分解为每分钟的平均值
- reactjs - 无法读取未定义的属性“地图”(帮帮我)
- java - 用于比较两个 Mats 时出现 countNonZero 错误
- java - Spring Boot - 验证相关实体的一对多关系