如果列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; jI'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电子表格中隐藏行?
发布评论