Google App脚本调用名为range getrange()异常:“区域坐标或尺寸无效”

发布于 2025-01-29 06:08:16 字数 1816 浏览 1 评论 0原文

以下功能是Google Sheet addon的一部分。 它读取了名为范围的所有电子表格的列表,并返回map()的结果 - 命名范围的名称及其A1notations地址的数组。

const _SS = (() => SpreadsheetApp.getActive());

function getNRList() {
    let nrs = _SS().getNamedRanges();

    return nrs.map(nr => {
      let obj = {};
      //NR range
      obj.name = nr.getName();
      //NR add
      obj.fullA1Notation = util.getFullAdd("", "", nr.getRange());
  
      return obj;
    });
  }

util.getfulladd是内部函数返回的情况,在这种情况下,当前命名范围的完整a1notation。

此功能通常可以顺利运行,没有任何问题。

但是对于一个命名范围(或电子表格也许是电子表格??),发生了以下例外:

"Exception: Koordinaten oder Abmessungen des Bereichs sind ungültig.
    at ServerJS/clientInterface:23:55
    at Array.map (<anonymous>)
    at getNRList (ServerJS/clientInterface:18:16)
    at excuteUserRequest (ServerJS/AddOn:456:24)
    at __GS_INTERNAL_top_function_call__.gs:1:8"

由于某种原因,该消息是德语的,可能是因为用户语言环境的含义是Google Translate的含义是:

坐标或尺寸无效

根据呼叫堆栈(行= 23&amp; col = 55号),当调用nr.getRange()时,发生异常。

电子表格不是我所有的,而是对安装插件的用户之一。我只在记录器中看到例外。

实际上,它发生在代码中的另一个位置的同一用户&amp;电子表格,也循环循环列出循环中的命名范围列表到nr.getRange();

不同的插件任务&amp;流动,但完全相同。

我的假设是,该电子表格中指定范围的一个正在引起它。

由于我想了解可能发生这种情况的确切情况,因此我试图重新创建这样的例外,以确切查看如何处理它。

例如,我尝试定义命名范围,例如:表:

工作表有999行和26列(到Col Z),并将范围设置为AD1500。如图像中所见,这将失败。

但是,可以通过代码drevesheet.setnameDrange(名称,范围) - 第二个示例来进行。

我还尝试

  • 在表格中命名范围,然后删除表格
  • 将命名范围设置为表格中的最后一行 - 然后删除行。 在这两种情况下,它都变成了#ref,

所有这些命名范围都通过了该功能而没有任何例外。

知道这怎么可能发生?

The following function is part of Google sheet addon.
It reads the list of all the spreadsheet named ranges, and return the result of map() - an array of named ranges names and their A1Notations addresses.

const _SS = (() => SpreadsheetApp.getActive());

function getNRList() {
    let nrs = _SS().getNamedRanges();

    return nrs.map(nr => {
      let obj = {};
      //NR range
      obj.name = nr.getName();
      //NR add
      obj.fullA1Notation = util.getFullAdd("", "", nr.getRange());
  
      return obj;
    });
  }

util.getFullAdd is an internal function returns in this case the full a1Notation of the current named range.

This function usually runs smoothly with no problem.

but for one Named Range (or maybe spreadsheet??) the following exception occurred:

"Exception: Koordinaten oder Abmessungen des Bereichs sind ungültig.
    at ServerJS/clientInterface:23:55
    at Array.map (<anonymous>)
    at getNRList (ServerJS/clientInterface:18:16)
    at excuteUserRequest (ServerJS/AddOn:456:24)
    at __GS_INTERNAL_top_function_call__.gs:1:8"

For some reason the message is in German, probably because of the user locale the meaning by Google translate is :

coordinates or dimensions are invalid

According the call stack (row = 23 & col = 55 number) the exception occurs when nr.getRange() was called.

The spreadsheet is not own by me, but to one of the users installed the addon. I only see the exception in the logger.

It actually happened in another place in the code for the same user & spreadsheet, that also loop the list of named ranges calling inside the loop to nr.getRange();

Different addon task & flow, but the exact same issue.

My assumption that one on the named range in this spreadsheet is causing it.

As I want to understand the exact scenario when this might happen, I have tried to recreate such an exception to see exactly how to handle it.

I tried to defined named ranges giving "out of bound" range for example:

Sheet has 999 rows and 26 columns (up to col Z) and setting the range to AD1500. this fails as can be seen in the image.

It is possible however to do it by code SpreadSheet.setNamedRange(name,range)- 2nd example.

I also tried

  • named range inside a sheet and then deleted the sheet
  • set the named range to last row in the sheet - then delete the row.
    In both cases the it became #REF

All these named ranges passed the function without any exception.

Any idea how this can happen?

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑着哭最痛 2025-02-05 06:08:16

在A1表示法中获取名称和范围

function getNRList() {
  const ss = SpreadsheetApp.getActive();
  let nr = ss.getNamedRanges().filter(ob => ob.getName() && ob.getRange()).reduce((a,obj) => {
    a.list.push({ "name": obj.getName(), "range": obj.getRange().getA1Notation() })
    return a;
  },{list:[],getList: function(){return this.list}}).getList()
  Logger.log(JSON.stringify(nr));
}

Get namedRanges names and ranges in A1 notation

function getNRList() {
  const ss = SpreadsheetApp.getActive();
  let nr = ss.getNamedRanges().filter(ob => ob.getName() && ob.getRange()).reduce((a,obj) => {
    a.list.push({ "name": obj.getName(), "range": obj.getRange().getA1Notation() })
    return a;
  },{list:[],getList: function(){return this.list}}).getList()
  Logger.log(JSON.stringify(nr));
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文