-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsheets.ts
34 lines (32 loc) · 913 Bytes
/
sheets.ts
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
function sheetName() {
return SpreadsheetApp.getActiveSheet().getName();
}
function sortSheets() {
// @ts-ignore
fetchDayjs();
const monthNameToNumber = (name: string) => {
// @ts-ignore
const date = dayjs(name, "YYYY MMMM", true);
if (date.isValid()) {
return date.format("YYYY-MM");
}
return name;
};
const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
const sheets = spreadsheet.getSheets();
sheets.sort((a, b) =>
monthNameToNumber(a.getName()) > monthNameToNumber(b.getName()) ? -1 : 1
);
for (let i = 0; i < sheets.length; i++) {
spreadsheet.setActiveSheet(sheets[i]);
spreadsheet.moveActiveSheet(i + 1);
}
}
function deleteSheets() {
const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
for (const sheet of spreadsheet.getSheets()) {
if (sheet.getName().startsWith("20")) {
spreadsheet.deleteSheet(sheet);
}
}
}