-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB02. 2 Box formatting.js
More file actions
73 lines (61 loc) · 1.88 KB
/
B02. 2 Box formatting.js
File metadata and controls
73 lines (61 loc) · 1.88 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
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
function formatBox() {
const ui = DocumentApp.getUi();
try {
const doc = DocumentApp.getActiveDocument();
const documentId = doc.getId();
// Create namedRange for selected table
const namedRange = getSelectionCreateNamedRange(doc, documentId, 'TABLE');
if (namedRange.status == 'error') {
ui.alert(namedRange.message);
return 0;
}
const tableStartIndex = namedRange.startIndex;
const tableEndIndex = namedRange.endIndex;
const document = Docs.Documents.get(documentId);
const bodyElements = document.body.content;
let fTable;
for (let i in bodyElements) {
if (bodyElements[i].table) {
if (bodyElements[i].startIndex == tableStartIndex) {
if (bodyElements[i].endIndex == tableEndIndex) {
fTable = bodyElements[i];
break;
}
}
}
}
const requests = [];
const numRows = fTable.table.rows;
const numCols = fTable.table.columns;
tableStyle_ORANGE_BORDER.width.magnitude = 1.5;
requests.push(
{
updateTableCellStyle: {
tableRange: {
tableCellLocation: {
tableStartLocation: {
index: tableStartIndex
},
},
rowSpan: numRows,
columnSpan: numCols
},
tableCellStyle: {
borderTop: tableStyle_ORANGE_BORDER,
borderBottom: tableStyle_ORANGE_BORDER,
borderLeft: tableStyle_ORANGE_BORDER,
borderRight: tableStyle_ORANGE_BORDER,
},
fields: 'backgroundColor,borderBottom,borderLeft,borderRight,borderTop'
}
}
);
Docs.Documents.batchUpdate({
requests: requests
}, documentId);
}
catch (error) {
ui.alert('Error in formatBox: ' + error);
return 0;
}
}