You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Apps Script中onEdit事件获取单元格行列报错排查

问题解决:TypeError: RANGE.getCol is not a function

你遇到的错误是因为调用了Range类中不存在的方法——获取列索引的方法不是getCol(),正确的方法名称是getColumn(),getRow()的写法是没问题的,这纯粹是方法名拼写错误导致的。

修正后的代码如下:

function onEdit(e) {
  const RANGE = e.range;

  let row = RANGE.getRow();
  let col = RANGE.getColumn(); // 修正为getColumn()

  Logger.log('line : ', row, 'column : ', col)
}

修改后,当你编辑表格单元格时,就能在执行日志中正常输出被修改单元格的行号和列号了。

内容的提问来源于stack exchange,提问作者mthgn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 03:40:34