Created
February 9, 2011 12:36
-
-
Save sapegin/818396 to your computer and use it in GitHub Desktop.
Conditional rows formatting in Google Docs Spreadsheet
This file contains 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
var styles = { | |
'default': { | |
color: '#000', | |
background: '#fff', | |
style: 'normal' | |
}, | |
sent: { | |
color: '#ccc', | |
style: 'italic' | |
}, | |
asked: { | |
color: '#974841', | |
background: '#EBCA9D' | |
}, | |
answered: { | |
color: '#4F6228', | |
background: '#9BBB59' | |
} | |
}; | |
function onEdit(event) { | |
var sheet = event.source.getActiveSheet(); | |
if (sheet.getSheetName() != 'Обязательно') | |
return; | |
var rowIdx = event.source.getActiveRange().getRowIndex(); | |
if (getCellValue(sheet, rowIdx, 'F') == 'Да') | |
appyStyle(sheet, rowIdx, 'answered'); | |
else if (getCellValue(sheet, rowIdx, 'E') == 'Да') | |
appyStyle(sheet, rowIdx, 'asked'); | |
else if (getCellValue(sheet, rowIdx, 'D')) | |
appyStyle(sheet, rowIdx, 'sent'); | |
else | |
appyStyle(sheet, rowIdx, 'default'); | |
} | |
function getCellValue(sheet, row, col) { | |
return sheet.getRange(col + row).getValue(); | |
} | |
function appyStyle(sheet, row, name) { | |
var style = styles[name]; | |
var defaults = styles['default']; | |
var range = sheet.getRange(row, 1, 1, sheet.getLastColumn()); | |
range.setFontColor(style.color || defaults.color); | |
range.setBackgroundColor(style.background || defaults.background); | |
range.setFontStyle(style.style || defaults.style); | |
} |
This file contains 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment