【发布时间】:2021-05-22 16:40:59
【问题描述】:
到目前为止,我一直在使用 SF 的答案从一个范围中获取最后一个非空行:
=INDEX( FILTER( A4:D ; NOT( ISBLANK( A4:A ) ) ) ; ROWS( FILTER( A4:A ; NOT( ISBLANK( A4:A ) ) ) ) )
因为我开始经常使用它,所以我选择了一个脚本:
/* E.g. GETLASTNECELL(A4:A) */
function GETLASTNECELL(input) {
if (!Array.isArray(input)) {
throw new Error("Must be range")
}
if (input.map(col => col.length).sort()[0] !== 1) {
throw new Error("Range must be a single column")
}
const col = input
.map(row => row[0]) // get value
.filter(val => typeof val !== 'undefined' && val.toString().length > 0) // empty
return col[col.length - 1]
}
问题是这个功能真的很慢......它只是谷歌脚本生命周期的副产品吗?本机公式方法会立即显示结果。 (在 40x40 的小型电子表格上测试)
阅读:
【问题讨论】:
-
用于澄清目的。你说你在
40x40电子表格上测试了这个公式。我测试了您的公式,并意识到它仅适用于单列。如果您看到错误消息,您有Error("Range must be a single column")。你如何执行它?你传递什么作为参数? -
“真实”范围,例如
GETLASTNECELL(A4:A)
标签: google-apps-script google-sheets