-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateLetters.ts
More file actions
31 lines (20 loc) · 1.2 KB
/
createLetters.ts
File metadata and controls
31 lines (20 loc) · 1.2 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
import * as xlsx from 'xlsx';
const inputWorkbook = xlsx.readFile('panelists-template.xlsx');
const inputWorksheet = inputWorkbook.Sheets[inputWorkbook.SheetNames[0]];
const inputArray = xlsx.utils.sheet_to_json(inputWorksheet, { header: 1 }) as string[][];
const template = `Добрый день!
[0], приглашаю Вас принять участие в zoom-вебинаре Челябинского Тракторного завода.
Вы выступаете в [1], ваше выступление начинается после выступления [2].
Ваша ссылка на вход — [3].
С уважением, PR-служба Челябинского тракторного.`
const substitute = (data: string[]) =>
data.reduce((currentTemplate, currentValue, currentIndex) => currentTemplate.replace(`[${currentIndex}]`, currentValue), template)
const result = inputArray
.map(value => substitute(value))
.map(substituted => [substituted]);
const filename = "letters.xlsx";
const wsName = "Письма";
const wb = xlsx.utils.book_new();
const ws = xlsx.utils.aoa_to_sheet(result);
xlsx.utils.book_append_sheet(wb, ws, wsName);
xlsx.writeFile(wb, filename);