This repository has been archived by the owner on Dec 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GoogleSheet.js
77 lines (73 loc) · 2.07 KB
/
GoogleSheet.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
75
76
77
/**
* Retrieve the value from a given cell in a given sheet
*
* @param {number} row of cell
* @param {number} column of cell
* @param {Sheet} sheet from which to retrieve data
* @return {string} Data in the specified cell or undefined if out of bounds
*/
function getValue(row, column, sheet) {
var range = sheet.getDataRange();
var data = range.getValues();
if (range.getNumRows() < row + 1) {
return undefined;
} else if (range.getNumColumns() < column + 1) {
return undefined;
} else {
return data[row][column];
}
}
/**
* Set the value off a given cell in a given sheet
*
* @param {number} row of cell
* @param {number} column of cell
* @param {Sheet} sheet from which to retrieve data
* @param {string} value to be set in cell
*/
function setValue(row, column, sheet, value) {
if (sheet.rows < row + 1) {
var rij = [];
rij.push(value);
sheet.appendRow(rij);
} else {
var cell = sheet.getRange(row + 1, column + 1, 1, 1);
cell.setValue(value);
}
}
/**
* Set cell the background color of a given cell in a given sheet
*
* @param {number} row of cell
* @param {number} rolumn of cell
* @param {Sheet} sheet from which to retrieve data
* @param {string} backgroundcolor to be set
*/
function setBackgroundColor(row, column, sheet, backgroundcolor) {
if (sheet.rows < row + 1) {
var rij = [];
rij.push(value);
sheet.appendRow(rij);
} else {
var cell = sheet.getRange(row + 1, column + 1, 1, 1);
cell.setBackground(backgroundcolor);
}
}
/**
* Set the font color of a given cell in a given sheet
*
* @param {number} row of cell
* @param {number} column of cell
* @param {Sheet} sheet from which to retrieve data
* @param {string} fontcolor to be set
*/
function setFontColor(row, column, sheet, fontcolor) {
if (sheet.rows < row + 1) {
var rij = [];
rij.push(value);
sheet.appendRow(rij);
} else {
var cell = sheet.getRange(row + 1, column + 1, 1, 1);
cell.setFontColor(fontcolor);
}
}