如果列A为空,在Google电子表格中隐藏行? [英] Hide rows in google spreadsheet if Column A is empty?

查看:230
本文介绍了如果列A为空,在Google电子表格中隐藏行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果列A为空,我试图隐藏行。我想将其应用于特定工作表(第1周,第2周,第3周,第4周和第5周)。这是我到目前为止第1周的代码。



pre $函数ConditionalHideRow(){
var ss = SpreadsheetApp.getActiveSpreadsheet ();
var sheet = ss.getSheetByName(Week1);
var condition = sheet.getRange(A:A)。getValue();
if(condition =EMPTY){
sheet.hideRows(1,125)
}

编辑:奖金的问题,有没有一种方法,我可以让它来取消隐藏时,列A填充?我使用a =查询公式来填充我的电子表格,并且随着更多数据的添加,长度将需要改变。

我假设'EMPTY'并不是真正在col A中找到的字符串,并且您想要检查col A是否真的是空的?如果是这样,请尝试:

 函数hideRows(){
[Week1,Week2,Week3 ,Week4,Week5] forEach(function(s){
var sheet = SpreadsheetApp.getActive()
.getSheetByName(s)
sheet.getRange('A:A ')
.getValues()
.forEach(function(r,i){
if(!r [0])sheet.hideRows(i + 1)
}) ;
});
}

或者,对于更经典的方法:

  function hideRows2(){
var sheets = [Week1,Week2,Week3,Week4,Week5 ]。
for(var i = 0,sLen = sheets.length; i< sLen; i ++){
var sheet = SpreadsheetApp.getActive()
.getSheetByName(sheets [i])
var val = sheet.getRange('A:A')
.getValues();
for(var j = 0,vLen = val.length; j if(!val [j] [0])sheet.hideRows(j + 1)



code
$ b

确保你没有太多空白行(在数据的最后一行之后),因为这可能导致脚本执行超时。


I'm trying to hide rows if Column A is empty. I want to apply this to specific sheets (Week1, Week2, Week3, Week4 and Week5). This is the code I have so far for Week1.

 function ConditionalHideRow() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Week1");
  var condition = sheet.getRange("A:A").getValue();
  if (condition = "EMPTY") {
    sheet.hideRows(1,125)
   }    

EDIT: Bonus question, is there a way I can get it to unhide when Column A is filled? I'm using a =query formula to populate my spreadsheet and the length will need to change as more data is added.

解决方案

I assume 'EMPTY' is not really the string that is to be found in col A and you do want to check if col A is truely empty ? If so, try:

function hideRows() {
["Week1", "Week2", "Week3", "Week4", "Week5"].forEach(function (s) {
    var sheet = SpreadsheetApp.getActive()
        .getSheetByName(s)
    sheet.getRange('A:A')
        .getValues()
        .forEach(function (r, i) {
            if (!r[0]) sheet.hideRows(i + 1)
        });
    });
}

Or, for a more 'classical' approach:

function hideRows2() {
var sheets = ["Week1", "Week2", "Week3", "Week4", "Week5"];
for (var i = 0, sLen = sheets.length; i < sLen; i++) {
    var sheet = SpreadsheetApp.getActive()
        .getSheetByName(sheets[i])
    var val = sheet.getRange('A:A')
        .getValues();
    for (var j = 0, vLen = val.length; j < vLen; j++) {
        if (!val[j][0]) sheet.hideRows(j + 1)
        }
    }
}

Make sure to you don't have too many blank rows (after the last row with data) as that may lead to an execution time-out of the script.

这篇关于如果列A为空,在Google电子表格中隐藏行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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