[英]onEdit(e) in Google Script - trying to put last edited date in cell and exclude this functionality on certain sheets (tabs)
I'm working on a Google sheets script that enters the date of the last edit in a specific cell on all tabs except for the ones i specifically exclude. 我正在使用Google表格脚本,该脚本在所有标签上的特定单元格中输入上次编辑的日期,但我明确排除的日期除外。
My script currently looks like this, works, but does update on every tab instead of only the ones not specifically excluded. 我的脚本当前看起来像这样,可以运行,但是会在每个选项卡上更新,而不是仅在未明确排除的选项卡上更新。
function onEdit(e) {
if ((!e.value) &&
(SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getSheetName() !== "cheese" ||
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getSheetName() !== "ham" ||
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getSheetName() !== "toast" ||
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getSheetName() !== "butter" ||
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getSheetName() !== "popcicle" ||
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getSheetName() !== "cake" ||
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getSheetName() !== "meat"))
{
e.source.getActiveSheet().getRange('B5').setValue(new Date());
}
}
Any ideas? 有任何想法吗?
It's not clear to me what you were doing with !e.value. 我不清楚您对!e.value所做的事情。
Try this: 尝试这个:
function onEdit(e)
{
var excluded=['cheese','ham','toast','butter','popcicle','cake','meat']
if(excluded.indexOf(e.source.getActiveSheet().getName())>0)
{
e.source.getActiveSheet().getRange('B5').setValue(new Date());
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.