【问题标题】:google sheets script Get row index of last entry in a column谷歌表格脚本获取列中最后一个条目的行索引
【发布时间】:2016-07-12 17:44:01
【问题描述】:

我希望遍历列中的值。但是该列正在扩展,我不想每次希望在该列中添加另一个条目时都更改范围值。

Google 懒得添加调用行或列之类的基本功能,真是令人沮丧!

【问题讨论】:

    标签: google-apps-script google-sheets


    【解决方案1】:

    遍历列中的每个项目实际上非常简单。

    var column // int value of your column, 
               // assuming you know which column you want. 
               // (technically, your column number -1
    var numRows = yourSheet.getLastRow();
    
    for (var i; i < numRows; i++) {
      cell = table.getCell(i, column);
    
      // If you want to store all the cells text
      list.push(cell.getText());
    } 
    

    就这么简单。如果你想要表格的每个单元格,只需在 i 中循环 j,然后 getCell(i, j);

    【讨论】:

    • 这会遍历一列。我已经可以表演了。我正在寻找一种解决方案,其中列不断扩展到更多行,table 不能像您的示例那样是硬编码范围。
    • 我很抱歉,我应该说的是 sheet.getLastRow()。这将获得包含内容的最后一行,因此它将是运行时列的大小。
    • 是的,我刚刚使用了它,它正在工作。如果您愿意,您可以进行更改。我会接受你的回答。
    • 如果您投了反对票,请留言说明原因。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-26
    • 1970-01-01
    • 1970-01-01
    • 2022-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多