1

我想隐藏谷歌驱动器电子表格中在 A 列的单元格中没有任何值的所有行。然后能够在需要时再次查看它们。这个函数的脚本/公式是什么?谢谢

4

2 回答 2

3

更新以包括显示所有行的菜单:

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var range = sheet.getRange(1, 1, sheet.getLastRow());


function onOpen() {
    //add menu called Visibility onOpen
    ss.addMenu("Visibility", [{
        name: "Show All Rows", functionName: "showAllRows"
    }]);

    //get the values to those rows
    var values = range.getValues();

    //go through every row
    for (var i=0; i<values.length; i++){

        //if row value is equal to empty  
        if(values[i][0] === ""){

        //hide that row
        sheet.hideRows(i+1);   
        }   
    }
}

function showAllRows(){
    sheet.showRows(1,sheet.getLastRow());
}
于 2013-11-15T01:48:01.273 回答
0

我修改了 Blexy 的菜单以允许将空行隐藏为菜单项,而不是在 onOpen 期间这样做。

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0]; //Sheet1 is in Array[0]
var range = sheet.getRange(1, 1, sheet.getLastRow());


function onOpen() {
    //add menu called Visibility onOpen
    ss.addMenu("Visibility", 
               [{
                 name: "Show All Rows", functionName: "showAllRows"
                 },
                {
                 name: "Hide All Empty Rows", functionName: "hideAllEmptyRows"
                 }
               ]
              );
}

function showAllRows(){
    sheet.showRows(1,sheet.getLastRow());
}

function hideAllEmptyRows(){
  //get the values to those rows
    var values = range.getValues();

  //go through every row
  for (var i=0; i<values.length; i++){
        //if row value is equal to empty  
        if(values[i][0] === ""){

        //hide that row
        sheet.hideRows(i+1);   
        }   
    }

}
于 2016-05-03T01:28:21.183 回答