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

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

问题描述

所以我应该首先说我是Javascript /编程新手。我了解了它的一大部分,但实际上并没有真正知道我在做什么。

我试图使用谷歌脚本,因此当我打开电子表格时,光标从最后一行开始,这样我就可以使用键盘大师和苹果脚本输入文本。问题是,我似乎无法得到任何工作。我试着使用他们在这里的内容:更快地找到第一个空行,但似乎没有任何实际工作正常。该函数运行没有问题,但它从来没有实际做任何事情。我已经使用了建议的函数以及一些'getLastrow'的开发者函数,但没有任何结果。



我想我已经完成了第二部分,它在我打开文档时工作,我在打开时设置了一个触发器,但是我不能真正测试它,直到我得到主函数的工作。



非常感谢, -the-first-empty-row-google-apps-script>引用的问题提供了脚本,引用了电子表格中的第一个空行(尽管有些这些解决方案找到列A中的第一个空单元格,它不一定是一个空的,但我离题了。)



可以访问用户界面的电子表格附加脚本,您可以通过以下几种功能影响电子表格的活动视图:

  • Spreadsheet.setActiveRange() li>
  • Spreadsheet.setActiveSelection() (多种风格) Sheet.activate()

  • Range.activate()

  • ...还有其他一些功能会影响主动概念作为副作用。



  • 使用任何您希望识别活动电子表格中的空行的技术,此功能将选择移动到它,使用。 setActiveSelection()




    $ b

    / **
    *将当前用户的光标放入第一个空行的第一个单元格中。
    * /
    函数selectFirstEmptyRow(){
    var sheet = SpreadsheetApp.getActiveSpreadsheet();
    sheet.setActiveSelection(sheet.getRange(A+ getFirstEmptyRowWholeRow()))
    }

    如果您好奇, getFirstEmptyRowWholeRow()函数:

      / ** 
    * Mogsdad的整行检查器。
    * /
    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);
    }


    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.

    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.

    Many thanks,

    解决方案

    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:

    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()))
    }
    

    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);
    }
    

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

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