-
Notifications
You must be signed in to change notification settings - Fork 1
/
sheets.js
74 lines (71 loc) · 1.84 KB
/
sheets.js
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* Returns a sheet if only one parameter is specified else a range
*
* USAGES
* $('sheet1')
* $('sheet1', 'A1')
* $('sheet1', 1, 2)
* $('sheet1', 1, 2, 10, 10);
* $.sheet = $('sheet');
* $(1, 2)
* $(1, 2, 10, 10)
*/
function $(a, r, s, t, u) {
var sheet;
switch (typeof a) {
case 'string':
sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(a);
if ((typeof r) == 'undefined')
return sheet;
if ((typeof r) == 'number') {
if ((typeof t) == 'undefined')
return sheet.getRange(r, s);
return sheet.getRange(r, s, t, u);
} else
return sheet.getRange(r);
break;
case 'number':
sheet = $.sheet;
if ((typeof s) == 'undefined')
return sheet.getRange(a, r);
return sheet.getRange(a, r, s, t);
break;
default:
sheet = a;
if ((typeof r) == 'undefined')
return sheet;
if ((typeof r) == 'number') {
if ((typeof t) == 'undefined')
return sheet.getRange(r, s);
return sheet.getRange(r, s, t, u);
} else
return sheet.getRange(r);
}
}
// returns the row number of the cell where $value appears in $range
$.rowOf = function(value, range) {
let values = range.getValues();
for (let i = 0; i < values.length; i++) {
if (values[i] == value)
return range.getRow() + i;
}
return -1;
}
// returns the column number of the cell where $value appears in $range
$.columnOf = function (value, range) {
let values = range.getValues()[0];
for (let i = 0; i < values.length; i++) {
if (values[i] == value)
return range.getColumn() + i;
}
return -1;
}
$.vlookup = function(range, name, index = 1) {
let values = range.getValues();
for (let i = 0; i < values.length; i++) {
if (values[i][0] == name) {
return values[i][index];
}
}
return null;
};