4

I want to un-hide all the hidden rows and columns when I open the spreadsheet.

How can I do that for all sheets?

1 Answer 1

5

You can accomplish that with this piece of code.

Code

function onOpen() {
  // set up spreadsheet and sheet
  var ss = SpreadsheetApp.getActiveSpreadsheet(), sheets = ss.getSheets();

  for(var i = 0, iLen = sheets.length; i < iLen; i++) {
    // get sheet
    var sh = sheets[i];

    // unhide columns
    var rCols = sh.getRange("1:1");
    sh.unhideColumn(rCols);

    // unhide rows
    var rRows = sh.getRange("A:A");
    sh.unhideRow(rRows);
  }
}

Explained

The onOpen trigger will be activated upon opening of the spreadsheet. The script will find the outer bound of the sheet, for both columns and rows. First the columns are shown, followed by the rows. This code works for all sheets available.

Example

I've created an example file for you: unhide rows and columns upon opening

References

Edit

h/t : changed the code according to the suggestions AdamL made:

Two small possible performance gains:

  1. var sheets = ss.getSheets(); for (var i = 0, length = sheets.length; i < length; i++); var sh = sheets[i];
  2. can you do getRange("1:1")? (avoiding getMaxColumns call)
1
  • 3
    Hi Jacob; looks good. Two small possible performance gains: 1. var sheets = ss.getSheets(); for (var i = 0, length = sheets.length; i < length; i++); var sh = sheets[i]; and 2. can you do getRange("1:1")? (avoiding getMaxColumns call)
    – AdamL
    Sep 26, 2014 at 10:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.