forked from caenrigen/LatexKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreate Table Features.js
More file actions
156 lines (114 loc) · 4.12 KB
/
Copy pathCreate Table Features.js
File metadata and controls
156 lines (114 loc) · 4.12 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
function create_tableFeats(spec) {
var range = spec.range;
var values = range.getDisplayValues();
var numColumns = range.getNumColumns();
//***************** COLUMN FEATURES ARRAY CREATION *****************
// Array of ColFeat structures that saves the characteristics of each column
var colFeats = [];
for(var k=0;k<numColumns;k++)
colFeats[k] = colFeat();
// Start at top right corner and go throughout the matrix
// Stop when finding an "err" keyword
for(k=1;k<numColumns;k++)
for(var i=0;i<values.length;i++)
{
if(values[i][k] === getDevSettings().getErrorColumnTag())
{
colFeats[k - 1].set_pmError();
break;
}
if(values[i][k] === 'sd')
{
colFeats[k - 1].set_sdError();
}
}
// *************** END OF COLUMNS FEATURES CREATION *****************
// ***************** ROW FEATURES ARRAY CREATION ********************
// Local var for the range's values
var numRows = range.getNumRows();
// Array of rawFeat structures that saves the characteristics of each column
var rowFeats = [];
for(var k=0;k<=numRows;k++)
rowFeats[k] = rowFeat();
// ************** END OF ROW FEATURES CREATION **********************
// ***************** TEMPLATE CONFIGURATION *************************
var settingsArray = spec.settingsArray;
var sets = getTabSettingsFromArray(settingsArray);
var options = sets.getOptions();
var template = sets.getTemplate();
if(!template)
return {rowFeats: rowFeats, colFeats: colFeats};
if(options !== false && typeof options != 'number')
{
SpreadsheetApp.getUi().alert('Warning:\nField \'Options\' is invalid for NamedRange \''+sets.getRangeName()+'\'');
return {rowFeats: rowFeats, colFeats: colFeats};
}
template=template.toLowerCase();
// ********* HORIZON TEMPLATE *************
if(template === 'horizon' ){
rowFeats[0].set_hline();
rowFeats[numRows].set_hline();
if(options !== false && options <numRows && options>0)
rowFeats[options].set_hline();
if(sets.getBigstrut() === true)
set_bigstrut(rowFeats);
return {rowFeats: rowFeats, colFeats: colFeats};
}
// ********** END OF HORIZON ***************
// ********** BARCODE TEMPLATE *************
if(template === 'barcode'){
for(k=1 ; k<numColumns ; k++)
colFeats[k].set_lbar();
if(options !== false && options <numRows && options>0)
rowFeats[options].set_hline();
if(sets.getBigstrut() === true)
set_bigstrut(rowFeats);
return {rowFeats: rowFeats, colFeats: colFeats};
}
// ******** END OF BARCODE ******************
// ********* GRID TEMPLATE ******************
if(template === 'grid'){
if(options === 0){
for(k=1 ; k<numColumns ; k++)
colFeats[k].set_lbar();
for(k=1 ; k<numRows ; k++)
rowFeats[k].set_hline();
}
else if(options !== 0){
colFeats[0].set_lbar();
for(k=0 ; k<numColumns ; k++)
colFeats[k].set_rbar();
rowFeats[0].set_hline();
for(k=1 ; k<=numRows ; k++)
rowFeats[k].set_hline();
}
if(sets.getBigstrut() === true)
set_bigstrut(rowFeats);
return {rowFeats: rowFeats, colFeats: colFeats};
}
if(template === 'manual'){
var manualColSpec = '';
try{
manualColSpec = range.offset(-1, 0).getDisplayValue();
} catch(e){
// In case the table is at the top and there is no cell above
manualColSpec = '';
}
return {manual: true, rowFeats: rowFeats, colFeats: colFeats, manualColSpec: manualColSpec};
}
// If the code reached this point no template matches were found, warn the user
SpreadsheetApp.getUi().alert('Warning:\nInvalid Template for NamedRange '+sets.getRangeName());
return {rowFeats: rowFeats, colFeats: colFeats};
}
// Auxiliar function to configure bigstruts if need be
function set_bigstrut(rowFeats){
if(rowFeats[0].get_hline())
rowFeats[1].set_bigstrutTop();
for(var k=1; k < (rowFeats.length - 1) ; k++)
if(rowFeats[k].get_hline()){
rowFeats[k].set_bigstrutBot();
rowFeats[k+1].set_bigstrutTop();
}
if(rowFeats[k].get_hline())
rowFeats[k].set_bigstrutBot();
}