-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.js
More file actions
61 lines (52 loc) · 1.76 KB
/
Copy pathUtils.js
File metadata and controls
61 lines (52 loc) · 1.76 KB
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
function getCellValue(sheetName, cellAddress) {
const spreadsheet = SpreadsheetApp.getActiveSpreadsheet()
const sheet = spreadsheet.getSheetByName(sheetName);
if (!sheet) {
throw new Error(`Sheet with name "${sheetName}" does not exist!`);
}
const value = sheet.getRange(cellAddress).getValue();
return value;
}
function getParticipants(rows) {
return rows
.map(row => row[4])
.reduce((acc, namesString) => {
const names = namesString.split(", ");
for (const name of names) {
if (!acc.includes(name)) {
acc.push(name);
}
}
return acc;
}, []);
}
function deleteAllSheetsExcept(...sheetNames) {
const sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
sheets.forEach(sheet => {
const sheetName = sheet.getName();
if (!sheetNames.includes(sheetName)) {
SpreadsheetApp.getActiveSpreadsheet().deleteSheet(sheet);
}
});
}
function warnAndHideSheetsExceptRawAndNonEmptyRecommendation() {
const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
const sheets = spreadsheet.getSheets();
sheets.forEach(sheet => {
const name = sheet.getName();
const isRaw = name === "Raw";
const isRecommendation = name.startsWith("Recommendation");
const protections = sheet.getProtections(SpreadsheetApp.ProtectionType.SHEET);
protections.forEach(p => p.remove());
const protection = sheet.protect();
protection.setWarningOnly(true);
protection.setDescription("⚠️ This sheet is protected to prevent accidental edits. Please proceed only if you're sure.");
if (!isRaw && !isRecommendation) {
sheet.hideSheet();
} else if (isRecommendation && sheet.getLastRow() <= 1) {
sheet.hideSheet();
} else {
sheet.showSheet();
}
});
}