-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper functions.js
138 lines (104 loc) · 3.72 KB
/
helper functions.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
function appendToSheet(sheet, results) {
sheet.clearContents();
let metaData = results.getMetaData();
let numCols = metaData.getColumnCount();
const rows = [];
// First row with column labels
const colLabels = [];
for (let col = 0; col < numCols; col++) {
colLabels.push(metaData.getColumnLabel(col + 1));
}
rows.push(colLabels);
// Remaining rows with results
while (results.next()) {
const row = [];
for (let col = 0; col < numCols; col++) {
row.push(results.getString(col + 1));
}
rows.push(row);
}
// Find the last row containing a value
const lastRow = sheet.getDataRange().getLastRow();
// Set the values of the rows starting from the row below the last row containing a value
// or the top row if it is empty
let startRow = lastRow + 1;
const topRowValues = sheet.getRange(1, 1, 1, numCols).getValues();
if (topRowValues[0].every(value => value === "")) {
startRow = 1;
}
sheet.getRange(startRow, 1, rows.length, numCols).setValues(rows);
// Set the font size of the rows with column labels to 18
sheet.getRange(1, 1, 1, numCols).setFontSize(14);
sheet.autoResizeColumns(1, numCols + 1);
}
function setColoursFormat(sheet,cellrange,search, colour) {
// Adds a conditional format rule to a sheet that causes all cells in range A1:B3 to turn red
// if they contain a number between 1 and 10.
let range = sheet.getRange(cellrange);
var rule = SpreadsheetApp.newConditionalFormatRule()
.whenTextContains(search)
.setBackground(colour)
// .setTextStyle(0, 5, bold)
.setRanges([range])
.build()
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);
}
//setColoursFormatLessThanOrEqualTo(sheet, "O3:O1000",">=","30","#e0ffff")
function setColoursFormatLessThanOrEqualTo(sheet,cellrange, search, colour) {
// Adds a conditional format rule to a sheet that causes all cells in range A1:B3 to turn red
// if they contain a number between 1 and 10.
search = Number(search);
let range = sheet.getRange(cellrange);
var rule = SpreadsheetApp.newConditionalFormatRule()
.whenNumberLessThanOrEqualTo(search)
.setBackground(colour)
// .setTextStyle(0, 5, bold)
.setRanges([range])
.build()
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);
}
//setNumberFormat(sheet, "O3:O1000", "Rule")
function setNumberFormat(sheet,cellrange, format) {
let range = sheet.getRange(cellrange);
range.setNumberFormat(format);
}
function setTextFormat(sheet,cellrange,search, colour) {
// Adds a conditional format rule to a sheet that causes all cells in range A1:B3 to turn red
// if they contain a number between 1 and 10.
let range = sheet.getRange(cellrange);
var rule = SpreadsheetApp.newConditionalFormatRule()
.whenTextContains(search)
// .setBackground(colour)
.setFontColor(colour)
.setRanges([range])
.build()
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);
}
function setWrapped(sheet,cellrange) {
var cellrange = sheet.getRange(cellrange);
cellrange.setWrap(true);
}
function getIP() {
var url = "http://api.ipify.org";
var json = UrlFetchApp.fetch(url);
Logger.log(json);
}
function setupSheet(name){
// let sheet = setupSheet("Volunteering")
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName(name);
sheet.clearFormats();
return sheet
}
function setupCell(name,range){
// let cell = setupCell("Dashboard","B5")
var spreadsheet = SpreadsheetApp.getActive();
let sheet = spreadsheet.getSheetByName(name);
return sheet.getRange(range).getValues();
}