Created
December 9, 2012 08:55
-
-
Save hanxue/4243931 to your computer and use it in GitHub Desktop.
Highlighting alternate rows in Google Spreadsheets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function colorRowsAlternateSelection() { | |
var currentSheet = SpreadsheetApp.getActiveSheet(); | |
var currRange = currentSheet.getActiveSelection(); | |
topRow = currRange.getRow(); | |
buttomRow = currRange.getLastRow(); | |
leftCol = currRange.getColumn(); | |
rightCol = currRange.getLastColumn(); | |
colorRows(topRow , buttomRow , leftCol , rightCol ); | |
} | |
function colorColumns( topRow , buttomRow , leftCol , rightCol ) { | |
var currentSheet = SpreadsheetApp.getActiveSheet(); | |
for (i=leftCol; i<=rightCol; i++) { | |
if ( i % 2 == 0) { | |
currentSheet.getRange(topRow, i , (buttomRow-topRow)+1, 1 ).setBackgroundRGB(235, 235, 235); | |
} else { | |
currentSheet.getRange(topRow, i , (buttomRow-topRow)+1, 1 ).setBackgroundRGB(255, 255, 255); | |
} | |
} | |
} |
That was easy : add the following function to the native code :
function colorRows( topRow , buttomRow , leftCol , rightCol ) {
var currentSheet = SpreadsheetApp.getActiveSheet();
for (i=topRow; i<=buttomRow; i++) {
if ( i % 2 == 0) {
currentSheet.getRange(i, leftCol , 1, (rightCol-leftCol+1) ).setBackgroundRGB(235, 235, 235);
} else {
currentSheet.getRange(i, leftCol , 1, (rightCol-leftCol+1) ).setBackgroundRGB(255, 255, 255);
}
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry, but this raises an exception since the "colorRows" function is not defined.
If you replace the second function name by "colorRows", you get colored columns.
I'm going to look for a fix.