首页 > 解决方案 > 在工作表中搜索特定文本并根据其内容向该单元格添加注释

问题描述

我希望在工作表中添加一个按钮,以便搜索人名并添加特定于人名的注释。到目前为止,我使用了一个 onEdit(e) 脚本,但这将是一个每月复制/粘贴的列表,而不是用户编辑的。但是,当将此转换为使用“按钮”运行的脚本时,我收到一个值错误。

      function onEdit(e){ 
       var notes = {
        'rep 1': 'Only works Sundays, off Thurdays',
        'rep 2': 'Saturdays and Sundays',
        'rep 3': 'Saturdays/Chats only',
        'rep 4': 'Saturdays',
        'rep 5': 'Every third shift', }
       if(notes[e.value.toLowerCase()]) {
         return e.range.setNote(notes[e.value.toLowerCase()]);}}

标签: javascriptgoogle-apps-scriptgoogle-sheets

解决方案


function iguessthis() {
  const notes = {'rep 1': 'Only works Sundays, off Thurdays','rep 2': 'Saturdays and Sundays','rep 3': 'Saturdays/Chats only','rep 4': 'Saturdays','rep 5': 'Every third shift'};
  let v = SpreadsheetApp.getActiveRange().getValue().toString().toLowerCase();
  if(notes.hasOwnProperty(v)) {
    SpreadsheetApp.getActiveRange().setNote(notes[v]);
  }
}

推荐阅读