-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiffSidebarCode.gs
42 lines (40 loc) · 1.37 KB
/
DiffSidebarCode.gs
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
function onOpen() {
SpreadsheetApp.getUi().createMenu('Diff Two Cells')
.addItem('Diff Two Cells', 'openDialog')
.addToUi();
}
function openDialog() {
const html = HtmlService.createHtmlOutputFromFile('DiffSidebar')
.setHeight(1500)
.setWidth(1500);
const selectedCells = getSelectedCells();
SpreadsheetApp.getUi().showModalDialog(html, 'Diff Result: ' + selectedCells.cell1 + ',' + selectedCells.cell2);
}
function getSelectedCells() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const ranges = sheet.getActiveRangeList().getRanges();
if (ranges.length === 0) {
return { cell1: 'No cells selected', cell2: ''}
}
if (ranges.length === 2) {
const cell1 = ranges[0].getCell(1, 1).getA1Notation();
const cell2 = ranges[1].getCell(1, 1).getA1Notation();
return {
cell1: cell1,
cell1Value: sheet.getRange(cell1).getValue(),
cell2: cell2,
cell2Value: sheet.getRange(cell2).getValue(),
};
}
if (ranges.length == 1) {
const cell1 = ranges[0].getCell(1, 1).getA1Notation();
const cell2 = ranges[0].getCell(ranges[0].getNumRows(), ranges[0].getNumColumns()).getA1Notation();
return {
cell1: cell1,
cell1Value: sheet.getRange(cell1).getValue(),
cell2: cell2,
cell2Value: sheet.getRange(cell2).getValue(),
};
}
return { cell1: 'Select two cells', cell2: '' }
}