如何删除Google电子表格中的所有NamedRanges [英] How to delete all NamedRanges in google spreadsheet

查看:70
本文介绍了如何删除Google电子表格中的所有NamedRanges的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的电子表格中有很多命名范围,有时我需要删除所有命名范围并创建一个新的范围.过去,我是通过删除工作表来完成此操作的,但是最近我发现此操作并未删除命名范围.因此,我尝试使用Class NamedRanges并按名称在第二行中列出它们,并一一删除它们,但这在我这里是行不通的:

I have a lot of named ranges in my spreadsheet and time to time I need to delete all of them and create new one. In past I did this by deleting worksheet but recently I've discovered that this operation is not deleting named ranges. So Ive tried to use Class NamedRanges and list trough them by name on second row and to remove them one by one but it doesn't work here is what I tried:

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();
         }
}

你能帮我吗?

推荐答案

实际上,我准备并运行了该脚本,该脚本有助于删除所有命名范围.

actually I prepared and ran this script which helped me remove ALL named ranges.

function removeNamedRanges(){
    var namedRanges = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getNamedRanges();
    for(i=0;i<namedRanges.length;i++){
        namedRanges[i].remove();
    } 
}

这篇关于如何删除Google电子表格中的所有NamedRanges的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆