如何选择谷歌电子表格/脚本中的第一个空行 [英] How do I select the first empty row in google spreadsheets/scripts

查看:13
本文介绍了如何选择谷歌电子表格/脚本中的第一个空行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我应该首先说我是 Javascript/编程的新手.我理解了很多,但在实际编写它时我真的不知道我在做什么.

So I should start by saying I'm new at Javascript/programming. I understand a good amount of it but don't really know what I'm doing when it comes to actually writing it.

我正在尝试使用 google 脚本,以便当我打开电子表格时,光标从最后一行开始,以便我可以使用键盘大师和苹果脚本的组合来输入文本.问题是,我似乎什么都做不了.我试过使用他们这里的东西:找到第一个空行的更快方法但似乎没有任何东西可以正常工作.该函数运行没有问题,但它实际上从未执行任何操作.我已经使用了建议的函数以及getLastrow"的一些开发人员的函数,但没有任何效果.

I'm trying to use google script so that when I open my spreadsheet, the cursor begins in the last row, so that I can use a combination of keyboard maestro and apple script to enter text. Problem is, I can't seem to get anything to work. I've tried to use what they have here: Faster way to find the first empty row but nothing seems to actually work properly. The function runs no problem, but it never actually does anything. I've used the suggested functions along with some of the developer ones of 'getLastrow" but nothing goes.

我想我已经完成了第二部分,以便在我打开文档时让它工作,我设置了一个打开时"触发器,但在我使主要功能工作之前我无法实际测试它.

I think I have the second part down, in that to get it to work when I open the document I set a trigger 'on open', but I can't actually test it until I get the main function working.

非常感谢,

推荐答案

引用的问题scripts 提供了对电子表格中第一个空行的引用.(...尽管其中一些解决方案会在 A 列中找到第一个空单元格,这不一定是空.但我离题了.)

The referenced question provides scripts with a reference to the first empty row in a spreadsheet. (...although some of those solutions find the first empty cell in column A, which isn't necessarily an empty row. But I digress.)

在可以访问用户界面的电子表格附加脚本中,您可以使用多种功能影响电子表格的活动视图:

In a spreadsheet-attached script with access to the User Interface, you can affect the active view of the spreadsheet with several functions:

使用您希望在活动电子表格中识别空行"的任何技术,此函数将使用.setActiveSelection()将选择移动到它:

Using whatever technique you wish to identify the "empty row" in the active spreadsheet, this function will move the selection to it, using .setActiveSelection():

/**
 * Place the current user's cursor into the first cell of the first empty row.
 */
function selectFirstEmptyRow() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet();
  sheet.setActiveSelection(sheet.getRange("A"+getFirstEmptyRowWholeRow()))
}

getFirstEmptyRowWholeRow() 函数,如果你很好奇:

The getFirstEmptyRowWholeRow() function, if you're curious:

/**
 * Mogsdad's "whole row" checker.
 */
function getFirstEmptyRowWholeRow() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var range = sheet.getDataRange();
  var values = range.getValues();
  var row = 0;
  for (var row=0; row<values.length; row++) {
    if (!values[row].join("")) break;
  }
  return (row+1);
}

这篇关于如何选择谷歌电子表格/脚本中的第一个空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆