google-apps-script - 将脚本运行到特定工作表 - Google 工作表
问题描述
我想知道如何修改我的脚本以针对特定选项卡(检查)而不是所有选项卡。下面是我的脚本:
function onEdit(e) {
var sheet, cols, colInd, offset, format;
sheet = e.source.getActiveSheet();
cols = [7,13,14,16];
colInd = cols.indexOf(e.range.columnStart);
if (colInd == -1) return;
if (colInd < 3) {
offset = [4,-1,1,1];
format = "MM/dd/yyyy HH:mm:ss";
e.range.offset(0, offset[colInd])
.setValue(Utilities.formatDate(new Date(), "GMT+8", format));
} else {
setValidation(e);
}
}
解决方案
如果您想在编辑文档中的任何工作表时获得对“检查”工作表的引用,则Raserhin的回答有效。
如果您只想在编辑“检查”表时运行代码,请使用以下代码。
function onEdit(e) {
var sheet, cols, colInd, offset, format;
sheet = e.source.getActiveSheet();
if (sheet.getName() === 'Check') { // Condition to check edited Sheet
cols = [7,13,14,16];
colInd = cols.indexOf(e.range.columnStart);
if (colInd == -1) return;
if (colInd < 3) {
offset = [4,-1,1,1]
format = "MM/dd/yyyy HH:mm:ss";
e.range.offset(0, offset[colInd])
.setValue(Utilities.formatDate(new Date(), "GMT+8", format));
} else {
setValidation(e);
}
}
}
推荐阅读
- python - 如何使用熊猫根据某些条件更改列的值?
- python - 为多元预测创建 LSTM 模型时遇到问题
- java - 如何在 Hibernate HSQL 数据库中创建视图
- c++ - 这个 Visual Studio 编译器错误“除以或除以零”是一个错误吗?
- macos - macOS 上的 Swiftui 表单标签对齐
- r - 将箱线图异常值放入表中
- java - Kafka Streams Initializer 对同一个键被多次调用
- javascript - 画布,画布弧,javascript
- ssis - SSIS条件拆分处理列中的空值和其他值
- python - 在 Python 中同时插入行