0
votes

I am trying to figure out how to access the Banding Class of methods for the SpreadsheetApp. This is not how to simply apply banding. Instead, I am trying to get the data related to a sheet that banding has been applied to.

Here is the Developers Documentation: https://developers.google.com/apps-script/reference/spreadsheet/banding

I can use .getBandings() but this simply confirms whether or not a banding exits in the sheet. There is no data as to the details of that banding. For example, I would like to return the range of the banding.

I also learned that when a banding is applied, the background color of the cell stays default, so I cannot utilize those methods to determine the details.

Here is the link to a Sheet with banding applied. I have added a few lines of script to show what getBandings() returns. Feel free to make a copy. https://docs.google.com/spreadsheets/d/1xRuwE8moueSY5ZizZcy6KPkVmhJmOITN9Bql7XgHY3g/edit#gid=0

Any advice on how to access/utilize the methods in the Banding class would be appreciated.


From a comment to an answer

I am trying figure out the list of methods that would open up that class in SpreadsheetApp. I have experimented with SpreadsheetApp, getActiveSheet, getSheetByName, getRange and more. I cannot figure out how to open up that set of commands in the Banding class.

1
I know you are looking for answers but I have been using Google Sheets for years now and never noticed Banding. I guess because I can't find any Menu option that applies banding. And if you look at Spreadsheet and Sheet class you can getBandings() but I don't see any way of applying bandings. How do you use it?TheWizEd
Banding within a sheet is the "Alternating Colors" option under the Format in the menu. When trying to accomplish the same task with Apps Script, it is called Banding. SpreadsheetApp.getActiveSheet(),.getRange(row, column).applyColumnBanding(bandingTheme)Justin Keene

1 Answers

0
votes

For example, I would like to return the range of the banding.

To get the range of a banding use the getRange() method of Class Banding


getBandings() returns an interable object. Below is a simple example of how to get the address of the range of a banding. It assumes that the spreadsheet has at least one banding.

function myFunction(){
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var bandings = spreasheet.getBandings();
  var range = bandings[0].getRange();
  Logger.log(range.getA1Notation());
}

Related