-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpreadSheetCache.gs
86 lines (71 loc) · 2.29 KB
/
SpreadSheetCache.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
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
75
76
77
78
79
80
81
82
83
84
85
86
/**
* class to cache the SpreadsheetApp
* @return {[type]} [description]
*/
SpreadSheetCache = function() {
var activeSheet = null,
activeRange = null,
activeCell = null,
activeSpreadSheet = null,
activeSheetValues = null,
activeSheetName=null,
activeLastColumn=null;
/**
* Returns a two-dimensional array of values, indexed by row, then by column for the whole sheet
* @return {array} a two-dimensional array of values
*/
this.getActiveSheetValues = function() {
var s;
if (!activeSheetValues) {
s = this.getActiveSheet();
activeSheetValues = s.getSheetValues(1, 1, s.getLastRow(), s.getLastColumn());
}
return activeSheetValues;
};
/**
* Gets the active sheet in a spreadsheet
* @return {object} the active sheet in the spreadsheet
*/
this.getActiveSheet = function() {
activeSheet = activeSheet || this.getActiveSpreadsheet().getActiveSheet();
return activeSheet;
};
/**
* Returns the currently active spreadsheet, or null if there is none.
* @return {object} the active Spreadsheet object
*/
this.getActiveSpreadsheet = function() {
activeSpreadSheet = activeSpreadSheet || SpreadsheetApp.getActiveSpreadsheet();
return activeSpreadSheet;
};
/**
* Returns the active range for the active sheet. Returns the range of cells that is currently considered active.
* @return {object} the active range
*/
this.getActiveRange = function() {
activeRange = activeRange || this.getActiveSheet().getActiveRange();
return activeRange;
};
/**
* Returns the active cell in this sheet.
* @return {object} the active cell
*/
this.getActiveCell = function() {
activeCell = activeCell || this.getActiveSheet().getActiveCell();
return activeCell;
};
/**
* Returns the name of the sheet
* @return {string} the name of the sheet
*/
this.getActiveSheetName=function(){
return (activeSheetName = activeSheetName || this.getActiveSheet().getName());
};
/**
* Returns the position of the last column that has content.
* @return {number} the last column of the sheet that contains content
*/
this.getActiveSheetLastColumn=function(){
return (activeLastColumn = activeLastColumn || this.getActiveSheetValues()[0].length);
};
};