Thursday, September 27, 2012

Script for Hiding or Unhiding Columns or Rows in a Sheet

Following is the script for Hiding or Unhiding Columns or Rows in a Sheet:


function HideColumn()
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = ss.getSheetByName("Sheet1");

  var datarange = s.hideColumns(2);//this will hide Column B
}

function unHideColumn()
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = ss.getSheetByName("Sheet1");

  var columnRange = s.getRange("B:B");
  var datarange = s.unhideColumn(columnRange);
}


function HideRow()
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = ss.getSheetByName("Sheet1");

  var datarange = s.hideRows(2);//this will hide Column B
}

function unHideRow()
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = ss.getSheetByName("Sheet1");

  var rowRange = s.getRange("A2:2");
  var datarange = s.unhideRow(rowRange);
}



And If you are not much familiar with scripts then check out the following link:
http://igoogledrive.blogspot.in/2012/08/how-to-write-script-in-google.html 

I hope the above solution will help you, and if you need more help then please do comment below on this blog itself, I will try to help you out.

I also take up private or confidential projects:

If this blog post was helpful to you, and if you think you want to help me too and make my this blog survive then please donate here: http://igoogledrive.blogspot.com/2012/09/donate.html 

Thanks,
Kishan,


2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. I see how to add triggers in gscript - but I'm curious how I can create a button on the gsheet that triggers one of the 'trigger functions, which are basic (form, edit, open, change)?

    ReplyDelete