类型错误:无法读取未定义的属性(读取’getFormula’)

huangapple go评论64阅读模式
英文:

TypeError: Cannot read properties of undefined (reading 'getFormula')

问题

我正在尝试创建一个函数,该函数从单元格中获取一个公式,使用const formula = cell.getFormulas();,然后将该公式嵌入到我正在编写的脚本中。但是似乎没有任何运行结果... 有谁知道解决方法吗?谢谢!

function function_1(cell) {
      const formula = cell.getFormulas();
      ......

我试图在我的函数给我一个单元格参数后,从该单元格中获取一个公式。我只想获取通过参数传递的单元格中的公式。但实际上它并不起作用。

英文:

I'm trying to do a function that gets a formula from a cell with const formula = cell.getFormulas(); into a script that i'm doing. But nothing appears to run... Anyone knows a solution? Thanks!

function function_1(cell) {
const formula = cell.getFormulas();
......

I'm trying to take a formula from a cell once my function gives me a cell throw the param. I just want to get the formula that is inside the cell that is given throw the parameter. But actually didn't works.

答案1

得分: 1

只有range对象具有.getFormula()方法。如果cell不是一个范围,将抛出类型错误。

正如Tanaike这里提到的,脚本需要从范围的A1表示字符串中获取范围。脚本可以更改为以下内容:

function function_1(cell) {
  var ss = SpreadsheetApp.getActiveSheet();
  var formula = ss.getRange(cell).getFormulas();
  return(formula);
}

结果:

类型错误:无法读取未定义的属性(读取’getFormula’)

英文:

Only range objects have a .getFormula() method. If cell is not a range, a type error is thrown.

As Tanaike mentioned here, the script needs to get the range from the range's a1 notation string. The script can be changed to the following:

function function_1(cell) {
  var ss = SpreadsheetApp.getActiveSheet();
  var formula = ss.getRange(cell).getFormulas();
  return(formula);
}

Result:

类型错误:无法读取未定义的属性(读取’getFormula’)

huangapple
  • 本文由 发表于 2023年3月31日 19:08:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/75897836.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定