-
Notifications
You must be signed in to change notification settings - Fork 0
/
MacacaEAFE.txt
225 lines (214 loc) · 5.57 KB
/
MacacaEAFE.txt
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
GetDataRange =
/*
Get address range from start cell to end column
startCell: Start Cell
endColumn: End Column
*/
LAMBDA(startCell, endColumn,
LET(
startRow, ROW(startCell),
startCol, COLUMN(startCell),
endCol, COLUMN(endColumn),
lastRow, LOOKUP(2, 1 / (INDEX(INDIRECT(ADDRESS(startRow, startCol) & ":" & ADDRESS(1048576, startCol)), 0)<>""), ROW(INDIRECT(ADDRESS(startRow, startCol) & ":" & ADDRESS(1048576, startCol)))),
ADDRESS(startRow, startCol) & ":" & ADDRESS(lastRow, endCol)
)
);
JSON_VALUE_TRANSFORM =
/*
Transform a cell value into its JSON representation
value: Cell value to transform
*/
LAMBDA(value,
SWITCH(
TRUE,
ISBLANK(value), QUOTE(""),
ISNUMBER(value), value,
HASJSONSTRUCTURE(value), value,
value = TRUE(), "true",
value = FALSE(), "false",
value = NoData_Number(), "0",
value = NoData_ENUM(), "0",
value = NoData_Bool(), "false",
value = NoData_Json(), "{}",
value = NoData_Array(), "[]",
value = NoData_Text(), QUOTE(""),
QUOTE(value)
)
);
TOJSON =
/*
Convert table headers and data into a JSON array of objects
headers: Table headers
data: Table data
*/
LAMBDA(headers, data,
LET(
jsonArray,
BYROW(data,
LAMBDA(row,
LET(
jsonObject,
TEXTJOIN(",", TRUE,
BYCOL(row, LAMBDA(value,
LET(
colIndex, XMATCH(value, row, 0, 1),
key, INDEX(headers, 1, colIndex),
jsonValue, JSON_VALUE_TRANSFORM(value),
QUOTE(key) & ":" & jsonValue
)
))
),
"{" & jsonObject & "}"
)
)
),
"[" & TEXTJOIN(",", TRUE, jsonArray) & "]"
)
);
QUOTE =
/*
Add double quotes around a text value
text: Text value to quote
*/
LAMBDA(text, CHAR(34) & text & CHAR(34));
HASJSONSTRUCTURE =
/*
Check if a text value has JSON structure
text: Text value to check
*/
LAMBDA(text,
LET(
firstChar, LEFT(text, 1),
lastChar, RIGHT(text, 1),
AND(
OR(firstChar = "{", firstChar = "["),
OR(lastChar = "}", lastChar = "]")
)
)
);
ToCSharpEnum =
/*
Convert two lists into a C# enum definition
items: List of enum names
values: List of enum values
*/
LAMBDA(items, values,
LET(
itemsCount, COUNTA(items),
valuesCount, COUNTA(values),
IF(
itemsCount <> valuesCount,
"length not equal!",
LET(
result,
TEXTJOIN(", " & CHAR(10), TRUE,
BYROW(SEQUENCE(itemsCount), LAMBDA(rowIndex,
INDEX(items, rowIndex) & " = " & INDEX(values, rowIndex)
))
),
result
)
)
)
);
TOJSONARRAY =
/*
Convert a range of values into a JSON array
range: Range of values to convert
*/
LAMBDA(range,
LET(
data, range,
jsonArray,
BYROW(data,
LAMBDA(row,
TEXTJOIN(",", TRUE,
BYCOL(row, LAMBDA(value,
JSON_VALUE_TRANSFORM(value)
))
)
)
),
"[" & TEXTJOIN(",", TRUE, jsonArray) & "]"
)
);
TOJSONDICTIONARY =
/*
Convert a key-value pair into a JSON dictionary
key: Dictionary key
value: Dictionary value
*/
LAMBDA(key, value,
LET(
jsonKey, QUOTE(key),
jsonValue, JSON_VALUE_TRANSFORM(value),
"{" & jsonKey & ":" & jsonValue & "}"
)
);
TOJSONOBJECT =
/*
Convert two ranges of keys and values into a JSON object
keysRange: Range of keys
valuesRange: Range of values
*/
LAMBDA(keysRange, valuesRange,
LET(
keys, keysRange,
values, valuesRange,
numKeys, COUNTA(keys),
numValues, COUNTA(values),
IF(
numKeys <> numValues,
"Number of keys and values do not match",
LET(
jsonPairs,
BYCOL(SEQUENCE(1, numKeys), LAMBDA(colIndex,
LET(
key, INDEX(keys, colIndex),
value, INDEX(values, colIndex),
jsonValue, JSON_VALUE_TRANSFORM(value),
QUOTE(key) & ":" & jsonValue
)
)),
"{" & TEXTJOIN(",", TRUE, jsonPairs) & "}"
)
)
)
);
TOISO8601 =
/*
Convert a datetime value into ISO 8601 format
dateTime: Datetime value
timezone: Timezone offset in hours
*/
LAMBDA(dateTime, timezone,
LET(
adjustedDateTime, dateTime - timezone/24, // Adjust dateTime by timezone offset to convert to UTC
iso8601Format, "yyyy-mm-ddThh:MM:ss.000Z", // ISO 8601 format string with milliseconds and UTC indicator
iso8601DateTime, TEXT(adjustedDateTime, iso8601Format), // Convert adjusted dateTime to ISO 8601 formatted date and time
iso8601DateTime // Return the ISO 8601 formatted string ending with .000Z in UTC
)
);
CHECKINVALIDDATA =
/*
Check a range for invalid data (empty cells or cells containing whitespace)
range: Range of data to check
*/
LAMBDA(range,
LET(
invalidCells,
TEXTJOIN(", ", TRUE,
IF(ISBLANK(range), "Empty cells: " & ADDRESS(ROW(range), COLUMN(range)),
IF(ISNUMBER(FIND(" ", range)), "Cells containing whitespace: " & ADDRESS(ROW(range), COLUMN(range)), "")
)
),
IF(invalidCells = "", "Data valid!", invalidCells)
)
);
/* NoData define */
NoData_Number = LAMBDA("NoData_Number");
NoData_Text = LAMBDA("NoData_Text");
NoData_ENUM = LAMBDA("NoData_ENUM");
NoData_Bool = LAMBDA("NoData_Bool");
NoData_Json = LAMBDA("NoData_Json");
NoData_Array = LAMBDA("NoData_Array");