javascript - 在工作表中搜索特定文本并根据其内容向该单元格添加注释
问题描述
我希望在工作表中添加一个按钮,以便搜索人名并添加特定于人名的注释。到目前为止,我使用了一个 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()]);}}
解决方案
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]);
}
}
推荐阅读
- sprite-kit - 有没有办法将物理体限制在常规 n 边形内?
- elasticsearch - 在 Ubuntu 服务器上部署 Elasticsearch
- javascript - 有没有办法分析 PostgreSQL 查询以确保结果仅包含单个表中的列?
- java - DTO 中的动态字段类型
- deno - 创建 Deno https 服务器
- python - 如何将保存的模型转换为 tflite 文件?
- python-3.x - CNN Pytorch(FashionMNIST)中的train loss和test loss一样高
- electron-builder - 如何使用 gclient 获取电子分支代码?
- python - Python - 键错误:0
- javascript - 从客户端 JS 发送 JSON,服务器 Nodejs 读取为 [object object]