简体   繁体   English

Google脚本中的onEdit(e)-尝试将上次编辑的日期放在单元格中,并在某些工作表(标签)上排除此功能

[英]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.

相关问题 在 Google Sheets App Script 上同时运行的两个 onEdit(e) 函数 - two onEdit(e) functions running simulatenously on Google Sheets App Script Google文档脚本:将单元格移至onEdit上的其他两个工作表,但没有重复项 - Google Docs Script: Move cell to two other sheets onEdit but no duplicates 在Google表格中修改上一个单元格时的自动填充日期 - Auto-fill date when previous cell is edited in Google Sheets onEdit(e) 触发器在编辑单元格时不执行任何操作 - onEdit(e) trigger does nothing when cell is being edited 我怎样才能让一个单元格在编辑时发布它旁边的编辑日期? 在 Google 表格中使用 Google Apps 脚本 - How can I have a cell that when edited publishes it's edit date next to it? In Google Sheets using a Google Apps Script Google Sheets onEdit 函数跳转到 A1 单元格 - Google Sheets onEdit function jumping to A1 cell Google脚本-如果某个单元格被编辑,会自动发送电子邮件吗? - Google Script - Automatically send email IF a certain cell is edited? Google Sheets onEdit(e) TypeError:无法读取属性 - Google Sheets onEdit(e) TypeError: cannot read property 检查是否已编辑一个月的Google表格单元格 - Check if Google Sheets Cell is Edited for a Month Google Sheets 使用 onEdit 函数创建随机单元格边框 - Google Sheets Creates Random Cell Border with onEdit Function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM