如果列A为空,在Google电子表格中隐藏行?

编程入门 行业动态 更新时间:2024-10-26 11:20:26
本文介绍了如果列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 确保你没有太多空白行(在数据的最后一行之后),因为这可能导致脚本执行超时。

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电子表格中隐藏行?

本文发布于:2023-11-11 10:21:15,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:为空   电子表格   Google

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!