Skip to content

Commit 091a4c1

Browse files
committed
Merge remote-tracking branch 'origin/selectionChange-trigger-samples'
2 parents 9b81fce + 6ebd14e commit 091a4c1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

triggers/triggers.gs

+17
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ function onEdit(e) {
2424
}
2525
// [END apps_script_triggers_onedit]
2626

27+
// [START apps_script_triggers_onselectionchange]
28+
/**
29+
* The event handler triggered when the selection changes in the spreadsheet.
30+
* @param {Event} e The onSelectionChange event.
31+
*/
32+
function onSelectionChange(e) {
33+
// Set background to red if a single empty cell is selected.
34+
var range = e.range;
35+
if(range.getNumRows() == 1
36+
&& range.getNumColumns() == 1
37+
&& range.getCell(1, 1).getValue() == "") {
38+
range.setBackground("red");
39+
}
40+
}
41+
// [END apps_script_triggers_onselectionchange]
42+
43+
2744
// [START apps_script_triggers_oninstall]
2845
/**
2946
* The event handler triggered when installing the add-on.

0 commit comments

Comments
 (0)