forked from apc-mhs/seniormap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrimmer.gs
32 lines (27 loc) · 801 Bytes
/
Trimmer.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function installTriggers() {
uninstallExistingTriggers();
ScriptApp
.newTrigger('onFormSubmit')
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
.onFormSubmit()
.create();
}
function onFormSubmit() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('raw');
var trimmableRange = sheet.getRange(2, 3, sheet.getMaxRows(), 4);
var data = trimmableRange.getValues();
for (let i = 0; i < data.length; i++) {
for (let j = 0; j < data[0].length; j++) {
if (data[i][j].trim) {
data[i][j] = data[i][j].trim();
}
}
}
trimmableRange.setValues(data);
}
function uninstallExistingTriggers() {
const allTriggers = ScriptApp.getProjectTriggers();
for (let trigger of allTriggers) {
ScriptApp.deleteTrigger(trigger);
}
}