我一直在使用脚本(@Tanaike稍加支持),当我从Google表格的下拉列表中选择某些信息时,该脚本可以显示注释。我使用的脚本如下:
eval
该脚本基本上可以在我命名的所有工作表中使用,并且当我在下拉菜单(在function onEdit(e) {
const range = e.range;
const sheetNames = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "14", "15", "17", "20", "23", "24", "25", "26", "27", "28", "31", "33", "35", "37", "40", "41", "42", "43", "44", "45", "46", "47", "50", "52", "55", "56", "57", "58", "59", "60", "66/0", "66/1", "66/2", "66/3", "66/4", "66/5", "66/6", "66/7", "66/8", "66/9", "67", "68", "69", "70", "71", "73", "76", "77", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92",,,];
if (sheetNames.some(s => range.getSheet().getSheetName() == s) && range.columnStart == 5) {
const object = {
AVD: "AV Dawson Middlesbrough",
BA: "Basford Hall, Crewe (FLR)",
BH: "Barrow Hill Roundhouse",
BKR: "Bo'ness & Kinneil Railway",
BN: "Bounds Green (LNER)",
CD: "Crewe Diesel (Locomotive Storage Ltd)",
CE: "Crewe Electric TMD",
CF: "Cardiff Canton",
CFT: "Cardiff Tidal",
ChaR: "Chasewater Railway",
CPRR: "Chinoor & Princes Risborough Railway",
CZ: "Central Rivers (Bombardier)",
DRM: "Doncaster Royal Mail Terminal",
EH: "Eastleigh (Arriva Traincare)",
EHY: "Eastleigh East Yard",
ELY: "Ely Papworth Sidings",
EML: "EMD Longport",
FX: "Felixstowe Docks",
HT: "Heaton, Newcastle",
IL: "Ilford (Greater Anglia)",
LA: "Laira (Great Western)",
LB: "Loughborough Brush Traction",
LD: "Leeds Midland Road (FLR)",
LE: "Landore (Great Western)",
LM: "Long Marston",
LR: "Leicester L.I.P (UKRL)",
NA: "Newton Aycliffe (Hitachi)",
NC: "Norwich Crown Point",
NM: "Nottingham Eastcroft",
PG: "Peterborough (GBRf)",
PM: "Bristol St Phillips Marsh",
RR: "Roberts Road, Doncaster",
SZ: "Southampton Maritime (FLR)",
TO: "Toton (DBC)",
TW: "Tonbridge West Yard",
TY: "Tyne Yard",
WB: "Wembley (Alstom)",
WEN: "Wensleydale Railway",
WI: "Wishaw",
ZB: "Doncaster Wabtec",
};
const v = range.getValue();
range.setNote(v in object ? object[v] : "");
}
}
中选择缩写之一时,便会自动显示一条注释,其中包含详细信息,即如果我选择“下拉菜单中的“ AVD”,便会出现一条注释,指出“ AV Dawson Middlesbrough”。
这很棒,并且完全按照我想要的方式工作。但是,现在我希望将其扩展到在下拉列表中使用缩写的其他列,因此我还设置了以下脚本:
column E
此脚本的工作原理与第一个脚本相同,但我要求它在电子表格的function onEdit(e) {
const range = e.range;
const sheetNames = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "14", "15", "17", "20", "23", "24", "25", "26", "27", "28", "31", "33", "35", "37", "40", "41", "42", "43", "44", "45", "46", "47", "50", "52", "55", "56", "57", "58", "59", "60", "66/0", "66/1", "66/2", "66/3", "66/4", "66/5", "66/6", "66/7", "66/8", "66/9", "67", "68", "69", "70", "71", "73", "76", "77", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92",,,];
if (sheetNames.some(s => range.getSheet().getSheetName() == s) && range.columnStart == 2) {
const object = {
ELR: "East Lancashire Railway",
HST: "Heritage Shunters Trust",
};
const v = range.getValue();
range.setNote(v in object ? object[v] : "");
}
}
中工作,该电子表格包含上述脚本中所示的不同数据。再次,作为示例,我要求它起作用,以便当我从下拉列表中选择“ HST”时,该单元格中会出现一条自动注释,说明“ Heritage Shunters Trust”。同样,我能够按需要使此脚本正常工作。
但是,我现在遇到的问题是我似乎无法同时运行两个脚本。因此,随着column B
的新脚本(我的问题中的第二个脚本)正常工作,column B
的脚本不再有效。
我怀疑这与脚本的column E
部分有关,因此我尝试向脚本中添加range.columnStart
,但是没有运气,并且用尽了其他所有精力我能想到的各种选择,我已经向你们寻求帮助,我们将不胜感激。
答案 0 :(得分:1)
为了能够在同一脚本中运行这两个功能,您将需要这两个功能的名称不同。
因此,您可以尝试将第二个功能重命名为onEdit2
。