This repository has been archived by the owner on Oct 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
79 lines (60 loc) · 2.29 KB
/
main.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
// ESLint global variables
/* global Corpus renderRichtext normalizeString matrice_forEach matrice_toArray array_toMatrice genColorMatrice splitByMotivesString */
/**
* The event handler triggered when opening the spreadsheet.
* @param {Event} event The onOpen event.
*/
function onOpen(event) {
// Add a custom menu to the spreadsheet.
SpreadsheetApp.getUi()
.createMenu("Fonctions personnalisées")
// Test
.addItem("Test", 'test')
/**
* Accentuer les différences des textes sélectionnés (un texte par cellule)
* en colorisant les mots selon leur caractère distinctif, en général et dans le texte en particulier.
*/
.addItem("Accentuer les différences", 'colorizeText')
.addItem("Uniformiser le texte", 'normalizeText')
.addItem("Retour à la ligne à chaque exposé de motif", 'splitByMotives')
.addToUi();
}
function test() {
// const sheet = SpreadsheetApp.getActiveSheet();
// const rng = sheet.getActiveRange();
}
function normalizeText() {
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getActiveRange();
const values = range.getValues();
const res = matrice_forEach(values, normalizeString);
range.setValues(res);
}
function splitByMotives() {
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getActiveRange();
const values = range.getValues();
const res = matrice_forEach(values, splitByMotivesString);
range.setValues(res);
}
function colorizeText() {
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getActiveRange();
const values = range.getValues();
const a = matrice_toArray(values);
const textsArray = a.array;
const indexes = a.indexes;
const topLeft = [0, 0, 190]; // Dark Blue
const botLeft = [200, 210, 245]; // Light Blue // rq: alternative: [195, 225, 240]
const topRight = [200, 0, 0]; // Dark Red
const botRight = [245, 210, 200]; // Light Red
const granularity = 101;
const colorMatrice = genColorMatrice(granularity, granularity, topLeft, topRight, botLeft, botRight);
const richTextValues = [];
const corpus = new Corpus(textsArray);
for (const text of corpus.texts) {
richTextValues.push(renderRichtext(text, colorMatrice));
}
const res = array_toMatrice(richTextValues, indexes);
range.setRichTextValues(res);
}