microsoft-graph 2.22.1 → 2.22.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/services/addressManipulation.d.ts +24 -4
- package/dist/cjs/services/addressManipulation.d.ts.map +1 -1
- package/dist/cjs/services/addressManipulation.js +70 -7
- package/dist/esm/services/addressManipulation.d.ts +24 -4
- package/dist/esm/services/addressManipulation.d.ts.map +1 -1
- package/dist/esm/services/addressManipulation.js +67 -5
- package/package.json +1 -1
|
@@ -130,7 +130,27 @@ export declare function countAddressRows(address: Address): number;
|
|
|
130
130
|
*/
|
|
131
131
|
export declare function countAddressColumns(address: Address): number;
|
|
132
132
|
/**
|
|
133
|
-
*
|
|
133
|
+
* Creates a range from a single cell address, extending by the specified number of rows and columns.
|
|
134
|
+
* If rows/cols is positive, the cell is the start of the range; if negative, the cell is the end of the range.
|
|
135
|
+
*
|
|
136
|
+
* @param cell - The cell address to use as the anchor.
|
|
137
|
+
* @param rows - The number of rows for the range. Positive: cell is start; Negative: cell is end.
|
|
138
|
+
* @param cols - The number of columns for the range. Positive: cell is start; Negative: cell is end.
|
|
139
|
+
* @returns The created address range.
|
|
140
|
+
*
|
|
141
|
+
* @throws {InvalidArgumentError} If the resulting address is out of bounds.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* // Creates a 2x2 range starting at B2
|
|
145
|
+
* cellToRangeAddress("B2", 2, 2); // "B2:C3"
|
|
146
|
+
* // Creates a 2x2 range ending at B2
|
|
147
|
+
* cellToRangeAddress("B2", -2, -2); // "A1:B2"
|
|
148
|
+
* // Creates a 2x2 range starting at C3, extending 2 rows down and 2 columns left
|
|
149
|
+
* cellToRangeAddress("B2", 2, -2)).toBe("A2:B3")
|
|
150
|
+
*/
|
|
151
|
+
export declare function cellToRangeAddress(cell: CellAddress, rows: number, cols: number): Address;
|
|
152
|
+
/**
|
|
153
|
+
* Extracts a sub-address from a spreadsheet-style A1 range (e.g., "A1:D10"),
|
|
134
154
|
* allowing skip and take semantics on both rows and columns.
|
|
135
155
|
*
|
|
136
156
|
* Supports negative values for `skipRows` and `skipCols` to count from the end.
|
|
@@ -149,9 +169,9 @@ export declare function countAddressColumns(address: Address): number;
|
|
|
149
169
|
* subaddress("A1:D10", 0, -1); // All but last row: "A1:D9"
|
|
150
170
|
* subaddress("A1:D10", 0, Infinity, -2, 1); // Second last column: "C1:C10"
|
|
151
171
|
*/
|
|
152
|
-
export declare function
|
|
172
|
+
export declare function subAddress(address: Address, skipRows?: number, takeRows?: number, skipCols?: number, takeCols?: number): Address;
|
|
153
173
|
/**
|
|
154
|
-
* Extracts a
|
|
174
|
+
* Extracts a sub-range from a WorkbookRangeRef using skip/take semantics.
|
|
155
175
|
* @param rangeRef Range reference to extract the sub-range from.
|
|
156
176
|
* @param skipRows Number of rows to skip. If negative, skips from the end. Default 0.
|
|
157
177
|
* @param takeRows Number of rows to take after skipping. If negative, excludes from the end. Default Infinity.
|
|
@@ -160,5 +180,5 @@ export declare function subaddress(address: Address, skipRows?: number, takeRows
|
|
|
160
180
|
* @returns Extracted sub-range reference.
|
|
161
181
|
* @throws InvalidArgumentError if the requested rows or columns exceed the available range.
|
|
162
182
|
*/
|
|
163
|
-
export declare function
|
|
183
|
+
export declare function subRange(rangeRef: WorkbookRangeRef, skipRows?: number, takeRows?: number, skipCols?: number, takeCols?: number): WorkbookRangeRef;
|
|
164
184
|
//# sourceMappingURL=addressManipulation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addressManipulation.d.ts","sourceRoot":"","sources":["../../../src/services/addressManipulation.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAoB,aAAa,EAAsB,UAAU,EAAmB,MAAM,sBAAsB,CAAC;AAGnJ,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"addressManipulation.d.ts","sourceRoot":"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Q,SAA2B,GAAG,gBAAgB,CAM3K"}
|
|
@@ -22,8 +22,9 @@ exports.isAllColumnsAddress = isAllColumnsAddress;
|
|
|
22
22
|
exports.isAllRowsAddress = isAllRowsAddress;
|
|
23
23
|
exports.countAddressRows = countAddressRows;
|
|
24
24
|
exports.countAddressColumns = countAddressColumns;
|
|
25
|
-
exports.
|
|
26
|
-
exports.
|
|
25
|
+
exports.cellToRangeAddress = cellToRangeAddress;
|
|
26
|
+
exports.subAddress = subAddress;
|
|
27
|
+
exports.subRange = subRange;
|
|
27
28
|
const InvalidArgumentError_ts_1 = __importDefault(require("../errors/InvalidArgumentError.js"));
|
|
28
29
|
const UnsupportedAddressTypeError_ts_1 = __importDefault(require("../errors/UnsupportedAddressTypeError.js"));
|
|
29
30
|
const addressOffset_ts_1 = require("./addressOffset.js");
|
|
@@ -32,6 +33,10 @@ const firstColumn = "A";
|
|
|
32
33
|
const lastColumn = "XFD";
|
|
33
34
|
const firstRow = "1";
|
|
34
35
|
const lastRow = "1048576";
|
|
36
|
+
const firstColumnOffset = (0, addressOffset_ts_1.columnAddressToOffset)(firstColumn);
|
|
37
|
+
const lastColumnOffset = (0, addressOffset_ts_1.columnAddressToOffset)(lastColumn);
|
|
38
|
+
const firstRowOffset = (0, addressOffset_ts_1.rowAddressToOffset)(firstRow);
|
|
39
|
+
const lastRowOffset = (0, addressOffset_ts_1.rowAddressToOffset)(lastRow);
|
|
35
40
|
const addressPattern = /^(?<sheet>(?:'[^']+'|[A-Za-z0-9_]+)!)?(?:(?<startColumn>[A-Z]+)?(?<startRow>\d+)?(?::(?<endColumn>[A-Z]+)?(?<endRow>\d+)?)?)$/;
|
|
36
41
|
/**
|
|
37
42
|
* Fixes address, removing an optional sheet prefix and ensuring it is a valid range.
|
|
@@ -280,7 +285,65 @@ function countAddressColumns(address) {
|
|
|
280
285
|
return (0, addressOffset_ts_1.columnAddressToOffset)(components.endColumn) - (0, addressOffset_ts_1.columnAddressToOffset)(components.startColumn) + 1;
|
|
281
286
|
}
|
|
282
287
|
/**
|
|
283
|
-
*
|
|
288
|
+
* Creates a range from a single cell address, extending by the specified number of rows and columns.
|
|
289
|
+
* If rows/cols is positive, the cell is the start of the range; if negative, the cell is the end of the range.
|
|
290
|
+
*
|
|
291
|
+
* @param cell - The cell address to use as the anchor.
|
|
292
|
+
* @param rows - The number of rows for the range. Positive: cell is start; Negative: cell is end.
|
|
293
|
+
* @param cols - The number of columns for the range. Positive: cell is start; Negative: cell is end.
|
|
294
|
+
* @returns The created address range.
|
|
295
|
+
*
|
|
296
|
+
* @throws {InvalidArgumentError} If the resulting address is out of bounds.
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* // Creates a 2x2 range starting at B2
|
|
300
|
+
* cellToRangeAddress("B2", 2, 2); // "B2:C3"
|
|
301
|
+
* // Creates a 2x2 range ending at B2
|
|
302
|
+
* cellToRangeAddress("B2", -2, -2); // "A1:B2"
|
|
303
|
+
* // Creates a 2x2 range starting at C3, extending 2 rows down and 2 columns left
|
|
304
|
+
* cellToRangeAddress("B2", 2, -2)).toBe("A2:B3")
|
|
305
|
+
*/
|
|
306
|
+
function cellToRangeAddress(cell, rows, cols) {
|
|
307
|
+
const { ax, ay } = (0, cartesianAddress_ts_1.addressToCartesian)(cell);
|
|
308
|
+
// Determine start and end coordinates
|
|
309
|
+
let startCol;
|
|
310
|
+
let endCol;
|
|
311
|
+
let startRow;
|
|
312
|
+
let endRow;
|
|
313
|
+
if (rows > 0) {
|
|
314
|
+
startRow = ay;
|
|
315
|
+
endRow = ay + rows - 1;
|
|
316
|
+
}
|
|
317
|
+
else if (rows < -1) {
|
|
318
|
+
startRow = ay + rows + 1;
|
|
319
|
+
endRow = ay;
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
throw new InvalidArgumentError_ts_1.default("rows must not be zero or -1");
|
|
323
|
+
}
|
|
324
|
+
if (cols > 0) {
|
|
325
|
+
startCol = ax;
|
|
326
|
+
endCol = ax + cols - 1;
|
|
327
|
+
}
|
|
328
|
+
else if (cols < -1) {
|
|
329
|
+
startCol = ax + cols + 1;
|
|
330
|
+
endCol = ax;
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
throw new InvalidArgumentError_ts_1.default("cols must not be zero or -1");
|
|
334
|
+
}
|
|
335
|
+
if (Math.min(startCol, endCol) < firstColumnOffset || Math.max(startCol, endCol) > lastColumnOffset || Math.min(startRow, endRow) < firstRowOffset || Math.max(startRow, endRow) > lastRowOffset) {
|
|
336
|
+
throw new InvalidArgumentError_ts_1.default(`Resulting address is out of bounds: rows [${Math.min(startRow, endRow) + 1},${Math.max(startRow, endRow) + 1}], cols [${Math.min(startCol, endCol) + 1},${Math.max(startCol, endCol) + 1}]`);
|
|
337
|
+
}
|
|
338
|
+
return (0, cartesianAddress_ts_1.cartesianToAddress)({
|
|
339
|
+
ax: Math.min(startCol, endCol),
|
|
340
|
+
bx: Math.max(startCol, endCol),
|
|
341
|
+
ay: Math.min(startRow, endRow),
|
|
342
|
+
by: Math.max(startRow, endRow),
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Extracts a sub-address from a spreadsheet-style A1 range (e.g., "A1:D10"),
|
|
284
347
|
* allowing skip and take semantics on both rows and columns.
|
|
285
348
|
*
|
|
286
349
|
* Supports negative values for `skipRows` and `skipCols` to count from the end.
|
|
@@ -299,7 +362,7 @@ function countAddressColumns(address) {
|
|
|
299
362
|
* subaddress("A1:D10", 0, -1); // All but last row: "A1:D9"
|
|
300
363
|
* subaddress("A1:D10", 0, Infinity, -2, 1); // Second last column: "C1:C10"
|
|
301
364
|
*/
|
|
302
|
-
function
|
|
365
|
+
function subAddress(address, skipRows = 0, takeRows = Number.POSITIVE_INFINITY, skipCols = 0, takeCols = Number.POSITIVE_INFINITY) {
|
|
303
366
|
const { ax, bx, ay, by } = (0, cartesianAddress_ts_1.addressToCartesian)(address);
|
|
304
367
|
const [startRow, endRow] = slice(ay, by, skipRows, takeRows);
|
|
305
368
|
const [startCol, endCol] = slice(ax, bx, skipCols, takeCols);
|
|
@@ -334,7 +397,7 @@ function subaddress(address, skipRows = 0, takeRows = Number.POSITIVE_INFINITY,
|
|
|
334
397
|
}
|
|
335
398
|
}
|
|
336
399
|
/**
|
|
337
|
-
* Extracts a
|
|
400
|
+
* Extracts a sub-range from a WorkbookRangeRef using skip/take semantics.
|
|
338
401
|
* @param rangeRef Range reference to extract the sub-range from.
|
|
339
402
|
* @param skipRows Number of rows to skip. If negative, skips from the end. Default 0.
|
|
340
403
|
* @param takeRows Number of rows to take after skipping. If negative, excludes from the end. Default Infinity.
|
|
@@ -343,8 +406,8 @@ function subaddress(address, skipRows = 0, takeRows = Number.POSITIVE_INFINITY,
|
|
|
343
406
|
* @returns Extracted sub-range reference.
|
|
344
407
|
* @throws InvalidArgumentError if the requested rows or columns exceed the available range.
|
|
345
408
|
*/
|
|
346
|
-
function
|
|
347
|
-
const address =
|
|
409
|
+
function subRange(rangeRef, skipRows = 0, takeRows = Number.POSITIVE_INFINITY, skipCols = 0, takeCols = Number.POSITIVE_INFINITY) {
|
|
410
|
+
const address = subAddress(rangeRef.address, skipRows, takeRows, skipCols, takeCols);
|
|
348
411
|
return {
|
|
349
412
|
...rangeRef,
|
|
350
413
|
address,
|
|
@@ -130,7 +130,27 @@ export declare function countAddressRows(address: Address): number;
|
|
|
130
130
|
*/
|
|
131
131
|
export declare function countAddressColumns(address: Address): number;
|
|
132
132
|
/**
|
|
133
|
-
*
|
|
133
|
+
* Creates a range from a single cell address, extending by the specified number of rows and columns.
|
|
134
|
+
* If rows/cols is positive, the cell is the start of the range; if negative, the cell is the end of the range.
|
|
135
|
+
*
|
|
136
|
+
* @param cell - The cell address to use as the anchor.
|
|
137
|
+
* @param rows - The number of rows for the range. Positive: cell is start; Negative: cell is end.
|
|
138
|
+
* @param cols - The number of columns for the range. Positive: cell is start; Negative: cell is end.
|
|
139
|
+
* @returns The created address range.
|
|
140
|
+
*
|
|
141
|
+
* @throws {InvalidArgumentError} If the resulting address is out of bounds.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* // Creates a 2x2 range starting at B2
|
|
145
|
+
* cellToRangeAddress("B2", 2, 2); // "B2:C3"
|
|
146
|
+
* // Creates a 2x2 range ending at B2
|
|
147
|
+
* cellToRangeAddress("B2", -2, -2); // "A1:B2"
|
|
148
|
+
* // Creates a 2x2 range starting at C3, extending 2 rows down and 2 columns left
|
|
149
|
+
* cellToRangeAddress("B2", 2, -2)).toBe("A2:B3")
|
|
150
|
+
*/
|
|
151
|
+
export declare function cellToRangeAddress(cell: CellAddress, rows: number, cols: number): Address;
|
|
152
|
+
/**
|
|
153
|
+
* Extracts a sub-address from a spreadsheet-style A1 range (e.g., "A1:D10"),
|
|
134
154
|
* allowing skip and take semantics on both rows and columns.
|
|
135
155
|
*
|
|
136
156
|
* Supports negative values for `skipRows` and `skipCols` to count from the end.
|
|
@@ -149,9 +169,9 @@ export declare function countAddressColumns(address: Address): number;
|
|
|
149
169
|
* subaddress("A1:D10", 0, -1); // All but last row: "A1:D9"
|
|
150
170
|
* subaddress("A1:D10", 0, Infinity, -2, 1); // Second last column: "C1:C10"
|
|
151
171
|
*/
|
|
152
|
-
export declare function
|
|
172
|
+
export declare function subAddress(address: Address, skipRows?: number, takeRows?: number, skipCols?: number, takeCols?: number): Address;
|
|
153
173
|
/**
|
|
154
|
-
* Extracts a
|
|
174
|
+
* Extracts a sub-range from a WorkbookRangeRef using skip/take semantics.
|
|
155
175
|
* @param rangeRef Range reference to extract the sub-range from.
|
|
156
176
|
* @param skipRows Number of rows to skip. If negative, skips from the end. Default 0.
|
|
157
177
|
* @param takeRows Number of rows to take after skipping. If negative, excludes from the end. Default Infinity.
|
|
@@ -160,5 +180,5 @@ export declare function subaddress(address: Address, skipRows?: number, takeRows
|
|
|
160
180
|
* @returns Extracted sub-range reference.
|
|
161
181
|
* @throws InvalidArgumentError if the requested rows or columns exceed the available range.
|
|
162
182
|
*/
|
|
163
|
-
export declare function
|
|
183
|
+
export declare function subRange(rangeRef: WorkbookRangeRef, skipRows?: number, takeRows?: number, skipCols?: number, takeCols?: number): WorkbookRangeRef;
|
|
164
184
|
//# sourceMappingURL=addressManipulation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addressManipulation.d.ts","sourceRoot":"","sources":["../../../src/services/addressManipulation.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAoB,aAAa,EAAsB,UAAU,EAAmB,MAAM,sBAAsB,CAAC;AAGnJ,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"addressManipulation.d.ts","sourceRoot":"","sources":["../../../src/services/addressManipulation.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAoB,aAAa,EAAsB,UAAU,EAAmB,MAAM,sBAAsB,CAAC;AAGnJ,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAuBtE,MAAM,MAAM,iBAAiB,GAAG;IAC/B,WAAW,EAAE,aAAa,CAAC;IAC3B,SAAS,EAAE,aAAa,CAAC;IACzB,QAAQ,EAAE,UAAU,CAAC;IACrB,MAAM,EAAE,UAAU,CAAC;CACnB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,UAAQ,GAAG,OAAO,CAE9E;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,iBAAiB,CAcpE;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,iBAAiB,EAAE,UAAU,UAAQ,GAAG,OAAO,CAsBzF;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,WAAW,CAGjE;AAED;;;;GAIG;AACH,wBAAgB,k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,CAG5D;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAuCzF;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,SAAI,EAAE,QAAQ,SAA2B,EAAE,QAAQ,SAAI,EAAE,QAAQ,SAA2B,GAAG,OAAO,CAqC1J;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,EAAE,QAAQ,SAAI,EAAE,QAAQ,SAA2B,EAAE,QAAQ,SAAI,EAAE,QAAQ,SAA2B,GAAG,gBAAgB,CAM3K"}
|
|
@@ -6,6 +6,10 @@ const firstColumn = "A";
|
|
|
6
6
|
const lastColumn = "XFD";
|
|
7
7
|
const firstRow = "1";
|
|
8
8
|
const lastRow = "1048576";
|
|
9
|
+
const firstColumnOffset = columnAddressToOffset(firstColumn);
|
|
10
|
+
const lastColumnOffset = columnAddressToOffset(lastColumn);
|
|
11
|
+
const firstRowOffset = rowAddressToOffset(firstRow);
|
|
12
|
+
const lastRowOffset = rowAddressToOffset(lastRow);
|
|
9
13
|
const addressPattern = /^(?<sheet>(?:'[^']+'|[A-Za-z0-9_]+)!)?(?:(?<startColumn>[A-Z]+)?(?<startRow>\d+)?(?::(?<endColumn>[A-Z]+)?(?<endRow>\d+)?)?)$/;
|
|
10
14
|
/**
|
|
11
15
|
* Fixes address, removing an optional sheet prefix and ensuring it is a valid range.
|
|
@@ -254,7 +258,65 @@ export function countAddressColumns(address) {
|
|
|
254
258
|
return columnAddressToOffset(components.endColumn) - columnAddressToOffset(components.startColumn) + 1;
|
|
255
259
|
}
|
|
256
260
|
/**
|
|
257
|
-
*
|
|
261
|
+
* Creates a range from a single cell address, extending by the specified number of rows and columns.
|
|
262
|
+
* If rows/cols is positive, the cell is the start of the range; if negative, the cell is the end of the range.
|
|
263
|
+
*
|
|
264
|
+
* @param cell - The cell address to use as the anchor.
|
|
265
|
+
* @param rows - The number of rows for the range. Positive: cell is start; Negative: cell is end.
|
|
266
|
+
* @param cols - The number of columns for the range. Positive: cell is start; Negative: cell is end.
|
|
267
|
+
* @returns The created address range.
|
|
268
|
+
*
|
|
269
|
+
* @throws {InvalidArgumentError} If the resulting address is out of bounds.
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* // Creates a 2x2 range starting at B2
|
|
273
|
+
* cellToRangeAddress("B2", 2, 2); // "B2:C3"
|
|
274
|
+
* // Creates a 2x2 range ending at B2
|
|
275
|
+
* cellToRangeAddress("B2", -2, -2); // "A1:B2"
|
|
276
|
+
* // Creates a 2x2 range starting at C3, extending 2 rows down and 2 columns left
|
|
277
|
+
* cellToRangeAddress("B2", 2, -2)).toBe("A2:B3")
|
|
278
|
+
*/
|
|
279
|
+
export function cellToRangeAddress(cell, rows, cols) {
|
|
280
|
+
const { ax, ay } = addressToCartesian(cell);
|
|
281
|
+
// Determine start and end coordinates
|
|
282
|
+
let startCol;
|
|
283
|
+
let endCol;
|
|
284
|
+
let startRow;
|
|
285
|
+
let endRow;
|
|
286
|
+
if (rows > 0) {
|
|
287
|
+
startRow = ay;
|
|
288
|
+
endRow = ay + rows - 1;
|
|
289
|
+
}
|
|
290
|
+
else if (rows < -1) {
|
|
291
|
+
startRow = ay + rows + 1;
|
|
292
|
+
endRow = ay;
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
throw new InvalidArgumentError("rows must not be zero or -1");
|
|
296
|
+
}
|
|
297
|
+
if (cols > 0) {
|
|
298
|
+
startCol = ax;
|
|
299
|
+
endCol = ax + cols - 1;
|
|
300
|
+
}
|
|
301
|
+
else if (cols < -1) {
|
|
302
|
+
startCol = ax + cols + 1;
|
|
303
|
+
endCol = ax;
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
throw new InvalidArgumentError("cols must not be zero or -1");
|
|
307
|
+
}
|
|
308
|
+
if (Math.min(startCol, endCol) < firstColumnOffset || Math.max(startCol, endCol) > lastColumnOffset || Math.min(startRow, endRow) < firstRowOffset || Math.max(startRow, endRow) > lastRowOffset) {
|
|
309
|
+
throw new InvalidArgumentError(`Resulting address is out of bounds: rows [${Math.min(startRow, endRow) + 1},${Math.max(startRow, endRow) + 1}], cols [${Math.min(startCol, endCol) + 1},${Math.max(startCol, endCol) + 1}]`);
|
|
310
|
+
}
|
|
311
|
+
return cartesianToAddress({
|
|
312
|
+
ax: Math.min(startCol, endCol),
|
|
313
|
+
bx: Math.max(startCol, endCol),
|
|
314
|
+
ay: Math.min(startRow, endRow),
|
|
315
|
+
by: Math.max(startRow, endRow),
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Extracts a sub-address from a spreadsheet-style A1 range (e.g., "A1:D10"),
|
|
258
320
|
* allowing skip and take semantics on both rows and columns.
|
|
259
321
|
*
|
|
260
322
|
* Supports negative values for `skipRows` and `skipCols` to count from the end.
|
|
@@ -273,7 +335,7 @@ export function countAddressColumns(address) {
|
|
|
273
335
|
* subaddress("A1:D10", 0, -1); // All but last row: "A1:D9"
|
|
274
336
|
* subaddress("A1:D10", 0, Infinity, -2, 1); // Second last column: "C1:C10"
|
|
275
337
|
*/
|
|
276
|
-
export function
|
|
338
|
+
export function subAddress(address, skipRows = 0, takeRows = Number.POSITIVE_INFINITY, skipCols = 0, takeCols = Number.POSITIVE_INFINITY) {
|
|
277
339
|
const { ax, bx, ay, by } = addressToCartesian(address);
|
|
278
340
|
const [startRow, endRow] = slice(ay, by, skipRows, takeRows);
|
|
279
341
|
const [startCol, endCol] = slice(ax, bx, skipCols, takeCols);
|
|
@@ -308,7 +370,7 @@ export function subaddress(address, skipRows = 0, takeRows = Number.POSITIVE_INF
|
|
|
308
370
|
}
|
|
309
371
|
}
|
|
310
372
|
/**
|
|
311
|
-
* Extracts a
|
|
373
|
+
* Extracts a sub-range from a WorkbookRangeRef using skip/take semantics.
|
|
312
374
|
* @param rangeRef Range reference to extract the sub-range from.
|
|
313
375
|
* @param skipRows Number of rows to skip. If negative, skips from the end. Default 0.
|
|
314
376
|
* @param takeRows Number of rows to take after skipping. If negative, excludes from the end. Default Infinity.
|
|
@@ -317,8 +379,8 @@ export function subaddress(address, skipRows = 0, takeRows = Number.POSITIVE_INF
|
|
|
317
379
|
* @returns Extracted sub-range reference.
|
|
318
380
|
* @throws InvalidArgumentError if the requested rows or columns exceed the available range.
|
|
319
381
|
*/
|
|
320
|
-
export function
|
|
321
|
-
const address =
|
|
382
|
+
export function subRange(rangeRef, skipRows = 0, takeRows = Number.POSITIVE_INFINITY, skipCols = 0, takeCols = Number.POSITIVE_INFINITY) {
|
|
383
|
+
const address = subAddress(rangeRef.address, skipRows, takeRows, skipCols, takeCols);
|
|
322
384
|
return {
|
|
323
385
|
...rangeRef,
|
|
324
386
|
address,
|