gpt4 book ai didi

javascript - Google Apps 脚本 - 查找电子表格中列的最后一个空行

转载 作者:行者123 更新时间:2023-12-02 14:08:22 24 4
gpt4 key购买 nike

我目前有一个像这样的脚本:(它将每分钟运行一次并获取任何值)

  // function 01
sheet2.getRange(sheet2.getLastRow() + 1, 1, 1, 6).setValues(values);

// function 02
sheet2.getRange(sheet2.getLastRow() + 1, 10, 1, 6).setValues(values);

它找到最后一行并设置下一行中的值。两者都有不同的功能。但目前它输出的是这样的。

当前输出:不好

// function 1 output here       // function 2 output here
------------------------------------------------------------
| A | B | C || | | |
------------------------------------------------------------
| | | || D | E | F |
------------------------------------------------------------
| | | || G | H | I |
------------------------------------------------------------
| J | K | L || | | |
------------------------------------------------------------

我希望像这样显示:

预期结果

------------------------------------------------------------
| A | B | C || D | E | F |
------------------------------------------------------------
| J | K | L || G | H | I |
------------------------------------------------------------
| | | || | | |
------------------------------------------------------------

希望我说得清楚。

最佳答案

尝试以下函数,稍加修改以传递 Mogsdad 于 2014 年 11 月 27 日为响应线程 Faster way to find the first empty row 为新工作表提供的解决方案中的列。

// Don's array approach - checks first column only
// With added stopping condition & correct result.
// From answer https://stackoverflow.com/a/9102463/1677912
// Added the passing of myColumn which needs to be a column range
// example use: var emptyRow = getFirstEmptyRowByColumnArray('B:B');
function getFirstEmptyRowByColumnArray(myColumn) {
var spr = SpreadsheetApp.getActiveSpreadsheet();
var column = spr.getRange(myColumn);
var values = column.getValues(); // get all data in one call
var ct = 0;
while ( values[ct] && values[ct][0] != "" ) {
ct++;
}
return (ct+1);
}

当然,如果您愿意,也可以将其编写为仅传递列并创建范围。

关于javascript - Google Apps 脚本 - 查找电子表格中列的最后一个空行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39859113/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com