我是 Google Sheets 环境的新手,我有限的 VBA 知识无济于事。我希望能够从谷歌表格上“光标”选择的一个或多个单元格中删除范围名称。
我确实管理了从工作表中删除所有命名范围的代码,但这不是我想要的。我们将不胜感激您的帮助。
这并不完全是您所要求的,但我相信它已经很接近了。
原始数据图片:
活动范围图像
运行代码后的范围图像:
function myFunk() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName("Sheet0");
const remove = sh.getActiveRangeList();
const rg = ss.getRangeByName('Array1');
const row = rg.getRow();
const col = rg.getColumn();
let vs = rg.getValues();
Logger.log('Before\n %s',JSON.stringify(vs).replace(/],/g,'],\n'));
remove.getRanges().forEach(r => r.setValue(""));
SpreadsheetApp.flush();
vs = rg.getValues()
Logger.log('After:\n %s',JSON.stringify(vs).replace(/],/g,'],\n'));
}
Execution log
9:01:23 AM Notice Execution started
9:01:23 AM Info Before
[[17,20,26,0,10],
[10,31,22,24,4],
[19,31,16,1,29],
[3,5,17,22,8],
[15,0,30,11,30],
[7,5,23,10,3]]
9:01:23 AM Info After:
[["",20,26,0,""],
[10,31,22,24,4],
[19,31,16,1,29],
[3,5,17,22,8],
[15,0,30,11,30],
["",5,23,10,""]]
9:01:25 AM Notice Execution completed