简体   繁体   English

如何让 Google 脚本在特定行范围内的特定列中隐藏带有空白或零的行?

[英]How do I get Google Script to hide rows with blanks or zeroes in a specific column, within a specific range of rows?

I'm new to coding, and this is my first question on stackoverflow.我是编码新手,这是我关于 stackoverflow 的第一个问题。

I want to hide every row within a range of rows that has a blank or zero in a specific column, in this case, column D.我想隐藏在特定列(在本例中为 D 列)中具有空白或零的行范围内的每一行。

This is the code I'm currently using:这是我目前使用的代码:

    var s = SpreadsheetApp.getActive().getSheetByName('Invoice Template');
        s.getRange('d:d')

It is hiding every row with a zero in it in the whole column, but I want it to hid only zeroes between rows 13 and 29.它在整列中隐藏每一行,其中包含一个零,但我希望它只隐藏第 13 行和第 29 行之间的零。

var s = SpreadsheetApp.getActive()
     .getSheetByName('Invoice Template');

s.getRange('d13:d29') // Here's the fix!
     .getValues()
     .forEach(function (r, i) {
        if (r[0] !== '' && r[0].toString()
            .charAt(0) == 0) s.hideRows(i + 1)
    });

You're selecting the whole column in your code using s.getRange('d:d') .您正在使用s.getRange('d:d')选择代码中的整列。 This should actually be s.getRange('d13:d29') to specify that you only want to process data between rows 13 and 29.这实际上应该是s.getRange('d13:d29')以指定您只想处理第 13 行和第 29 行之间的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM