英文:
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);
}
结果:
英文:
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:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论