我的电子表格中有很多命名范围,我不时需要删除所有范围并创建新范围。在过去,我通过删除工作表来做到这一点但最近我发现此操作没有删除命名范围。所以我试图使用Class NamedRanges并在第二行按名称列出它们并逐个删除它们但是它在我这里尝试的不是:
function CellNamerRemove()
{
// the purpose of the CellNamerRemove function is to automatically remove all range names the complete vertical CellRanges
// for each column that has a 'header' in the sheet called 'RawData'. The Quality purpose is to force
// Named-Links only to exist in referencing the raw data from the Starccm+ files
// get a reference to the RawData Spreadsheet
var thisSheetString = "RawData";
var maxRows = SpreadsheetApp.getActiveSheet().getMaxRows();
var lastColumn = SpreadsheetApp.getActiveSheet().getLastColumn();
// loop from 1st column ie 1 to lastColumn.
for(thisColumn = 1; thisColumn <= lastColumn;thisColumn++)
{
var thisName = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(thisSheetString).getRange(2, thisColumn, 1, 1).getValue();
var ss = SpreadsheetApp.getActiveSpreadsheet();
// ss.setNamedRange(trim(thisName), thisRange);
ss.getRangeByName(thisName).remove();
}
}
你能帮帮我吗?
答案 0 :(得分:1)
实际上我准备并运行了这个脚本,帮助我删除所有命名范围。
function removeNamedRanges(){
var namedRanges = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getNamedRanges();
for(i=0;i<namedRanges.length;i++){
namedRanges[i].remove();
}
}
答案 1 :(得分:0)
问题出在这一行:
ss.getRangeByName(thisName).remove();
应该是:
ss.removeNamedRange(thisName);