-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathAddComment.ts
More file actions
37 lines (33 loc) · 1.24 KB
/
AddComment.ts
File metadata and controls
37 lines (33 loc) · 1.24 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
function main(workbook: ExcelScript.Workbook) {
const employees = workbook.getWorksheet('Employees').getUsedRange().getTexts();
console.log(employees);
const scheduleSheet = workbook.getWorksheet('Schedule');
const table = scheduleSheet.getTables()[0];
const range = table.getRangeBetweenHeaderAndTotal();
const scheduleData = range.getTexts();
for (let i=0; i < scheduleData.length; i++) {
let eId = scheduleData[i][3];
let employeeInfo = employees.find(e => e[0] === eId);
if (employeeInfo) {
console.log("Found a match " + employeeInfo);
let adminNotes = scheduleData[i][4];
try {
let comment = workbook.getCommentByCell(range.getCell(i, 5));
comment.delete();
} catch {
console.log("Ignore if there is no existing comment in the cell");
}
workbook.addComment(range.getCell(i,5), {
mentions: [{
email: employeeInfo[1],
id: 0,
name: employeeInfo[2]
}],
richContent: `<at id=\"0\">${employeeInfo[2]}</at> ${adminNotes}`
}, ExcelScript.ContentType.mention);
} else {
console.log("No match for: " + eId);
}
}
return;
}