microsoft-graph 2.22.0 → 2.22.2
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 +47 -13
- package/dist/cjs/services/addressManipulation.d.ts.map +1 -1
- package/dist/cjs/services/addressManipulation.js +116 -38
- package/dist/esm/services/addressManipulation.d.ts +47 -13
- package/dist/esm/services/addressManipulation.d.ts.map +1 -1
- package/dist/esm/services/addressManipulation.js +114 -37
- package/package.json +1 -1
|
@@ -130,21 +130,55 @@ export declare function countAddressRows(address: Address): number;
|
|
|
130
130
|
*/
|
|
131
131
|
export declare function countAddressColumns(address: Address): number;
|
|
132
132
|
/**
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* @param
|
|
137
|
-
* @
|
|
138
|
-
* @
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
*
|
|
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 subrange from a spreadsheet-style A1 range (e.g., "A1:D10"),
|
|
154
|
+
* allowing skip and take semantics on both rows and columns.
|
|
155
|
+
*
|
|
156
|
+
* Supports negative values for `skipRows` and `skipCols` to count from the end.
|
|
157
|
+
* Supports negative values for `takeRows` and `takeCols` to exclude from the end after skipping.
|
|
158
|
+
*
|
|
159
|
+
* @param address - The original range in A1 notation (e.g., "A1:D10").
|
|
160
|
+
* @param skipRows - Number of rows to skip. If negative, skips that many rows from the end. Default is 0.
|
|
161
|
+
* @param takeRows - Number of rows to take after skipping. If negative, excludes that many rows from the end of the remaining rows. Default is Infinity.
|
|
162
|
+
* @param skipCols - Number of columns to skip. If negative, skips that many columns from the end. Default is 0.
|
|
163
|
+
* @param takeCols - Number of columns to take after skipping. If negative, excludes that many columns from the end of the remaining columns. Default is Infinity.
|
|
164
|
+
* @returns A new A1-style range representing the sliced subrange (e.g., "B2:C5").
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* subaddress("A1:D10", -1, 1); // Last row: "A10:D10"
|
|
168
|
+
* subaddress("A1:D10", -2, 1); // Second last row: "A9:D9"
|
|
169
|
+
* subaddress("A1:D10", 0, -1); // All but last row: "A1:D9"
|
|
170
|
+
* subaddress("A1:D10", 0, Infinity, -2, 1); // Second last column: "C1:C10"
|
|
171
|
+
*/
|
|
172
|
+
export declare function subAddress(address: Address, skipRows?: number, takeRows?: number, skipCols?: number, takeCols?: number): Address;
|
|
173
|
+
/**
|
|
174
|
+
* Extracts a subrange from a WorkbookRangeRef using skip/take semantics.
|
|
143
175
|
* @param rangeRef Range reference to extract the sub-range from.
|
|
144
|
-
* @param
|
|
145
|
-
* @param
|
|
176
|
+
* @param skipRows Number of rows to skip. If negative, skips from the end. Default 0.
|
|
177
|
+
* @param takeRows Number of rows to take after skipping. If negative, excludes from the end. Default Infinity.
|
|
178
|
+
* @param skipCols Number of columns to skip. If negative, skips from the end. Default 0.
|
|
179
|
+
* @param takeCols Number of columns to take after skipping. If negative, excludes from the end. Default Infinity.
|
|
146
180
|
* @returns Extracted sub-range reference.
|
|
147
181
|
* @throws InvalidArgumentError if the requested rows or columns exceed the available range.
|
|
148
182
|
*/
|
|
149
|
-
export declare function subrange(rangeRef: WorkbookRangeRef,
|
|
183
|
+
export declare function subrange(rangeRef: WorkbookRangeRef, skipRows?: number, takeRows?: number, skipCols?: number, takeCols?: number): WorkbookRangeRef;
|
|
150
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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7D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAG1D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAGzD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,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"}
|
|
@@ -22,7 +22,8 @@ exports.isAllColumnsAddress = isAllColumnsAddress;
|
|
|
22
22
|
exports.isAllRowsAddress = isAllRowsAddress;
|
|
23
23
|
exports.countAddressRows = countAddressRows;
|
|
24
24
|
exports.countAddressColumns = countAddressColumns;
|
|
25
|
-
exports.
|
|
25
|
+
exports.cellToRangeAddress = cellToRangeAddress;
|
|
26
|
+
exports.subAddress = subAddress;
|
|
26
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"));
|
|
@@ -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,56 +285,129 @@ 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
|
-
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
* @param
|
|
287
|
-
* @
|
|
288
|
-
* @
|
|
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")
|
|
289
305
|
*/
|
|
290
|
-
function
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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 subrange from a spreadsheet-style A1 range (e.g., "A1:D10"),
|
|
347
|
+
* allowing skip and take semantics on both rows and columns.
|
|
348
|
+
*
|
|
349
|
+
* Supports negative values for `skipRows` and `skipCols` to count from the end.
|
|
350
|
+
* Supports negative values for `takeRows` and `takeCols` to exclude from the end after skipping.
|
|
351
|
+
*
|
|
352
|
+
* @param address - The original range in A1 notation (e.g., "A1:D10").
|
|
353
|
+
* @param skipRows - Number of rows to skip. If negative, skips that many rows from the end. Default is 0.
|
|
354
|
+
* @param takeRows - Number of rows to take after skipping. If negative, excludes that many rows from the end of the remaining rows. Default is Infinity.
|
|
355
|
+
* @param skipCols - Number of columns to skip. If negative, skips that many columns from the end. Default is 0.
|
|
356
|
+
* @param takeCols - Number of columns to take after skipping. If negative, excludes that many columns from the end of the remaining columns. Default is Infinity.
|
|
357
|
+
* @returns A new A1-style range representing the sliced subrange (e.g., "B2:C5").
|
|
358
|
+
*
|
|
359
|
+
* @example
|
|
360
|
+
* subaddress("A1:D10", -1, 1); // Last row: "A10:D10"
|
|
361
|
+
* subaddress("A1:D10", -2, 1); // Second last row: "A9:D9"
|
|
362
|
+
* subaddress("A1:D10", 0, -1); // All but last row: "A1:D9"
|
|
363
|
+
* subaddress("A1:D10", 0, Infinity, -2, 1); // Second last column: "C1:C10"
|
|
364
|
+
*/
|
|
365
|
+
function subAddress(address, skipRows = 0, takeRows = Number.POSITIVE_INFINITY, skipCols = 0, takeCols = Number.POSITIVE_INFINITY) {
|
|
366
|
+
const { ax, bx, ay, by } = (0, cartesianAddress_ts_1.addressToCartesian)(address);
|
|
367
|
+
const [startRow, endRow] = slice(ay, by, skipRows, takeRows);
|
|
368
|
+
const [startCol, endCol] = slice(ax, bx, skipCols, takeCols);
|
|
369
|
+
if (startRow < ay || endRow > by || startRow > endRow || startCol < ax || endCol > bx || startCol > endCol) {
|
|
370
|
+
throw new InvalidArgumentError_ts_1.default(`Requested subaddress is out of bounds: rows [${startRow + 1},${endRow + 1}], cols [${startCol + 1},${endCol + 1}] in range.`);
|
|
371
|
+
}
|
|
372
|
+
return (0, cartesianAddress_ts_1.cartesianToAddress)({
|
|
373
|
+
ay: startRow,
|
|
374
|
+
by: endRow,
|
|
375
|
+
ax: startCol,
|
|
376
|
+
bx: endCol,
|
|
377
|
+
});
|
|
378
|
+
function slice(start, end, skip, take) {
|
|
379
|
+
let s = start;
|
|
380
|
+
let e = end;
|
|
381
|
+
if (skip > 0) {
|
|
382
|
+
s = start + skip;
|
|
299
383
|
}
|
|
300
|
-
else if (
|
|
301
|
-
|
|
384
|
+
else if (skip < 0) {
|
|
385
|
+
s = end + skip + 1;
|
|
302
386
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
const colCount = bx - ax + 1;
|
|
306
|
-
if (Math.abs(cols) > colCount) {
|
|
307
|
-
throw new InvalidArgumentError_ts_1.default(`Requested columns (${cols}) exceed available columns (${colCount}) in range.`);
|
|
387
|
+
if (!Number.isFinite(take)) {
|
|
388
|
+
// do nothing
|
|
308
389
|
}
|
|
309
|
-
if (
|
|
310
|
-
|
|
390
|
+
else if (take >= 0) {
|
|
391
|
+
e = s + take - 1;
|
|
311
392
|
}
|
|
312
|
-
else if (
|
|
313
|
-
|
|
393
|
+
else if (take < 0) {
|
|
394
|
+
e += take;
|
|
314
395
|
}
|
|
396
|
+
return [s, e];
|
|
315
397
|
}
|
|
316
|
-
return (0, cartesianAddress_ts_1.cartesianToAddress)({
|
|
317
|
-
ay,
|
|
318
|
-
by,
|
|
319
|
-
ax,
|
|
320
|
-
bx,
|
|
321
|
-
});
|
|
322
398
|
}
|
|
323
399
|
/**
|
|
324
|
-
* Extracts a
|
|
400
|
+
* Extracts a subrange from a WorkbookRangeRef using skip/take semantics.
|
|
325
401
|
* @param rangeRef Range reference to extract the sub-range from.
|
|
326
|
-
* @param
|
|
327
|
-
* @param
|
|
402
|
+
* @param skipRows Number of rows to skip. If negative, skips from the end. Default 0.
|
|
403
|
+
* @param takeRows Number of rows to take after skipping. If negative, excludes from the end. Default Infinity.
|
|
404
|
+
* @param skipCols Number of columns to skip. If negative, skips from the end. Default 0.
|
|
405
|
+
* @param takeCols Number of columns to take after skipping. If negative, excludes from the end. Default Infinity.
|
|
328
406
|
* @returns Extracted sub-range reference.
|
|
329
407
|
* @throws InvalidArgumentError if the requested rows or columns exceed the available range.
|
|
330
408
|
*/
|
|
331
|
-
function subrange(rangeRef,
|
|
332
|
-
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);
|
|
333
411
|
return {
|
|
334
412
|
...rangeRef,
|
|
335
413
|
address,
|
|
@@ -130,21 +130,55 @@ export declare function countAddressRows(address: Address): number;
|
|
|
130
130
|
*/
|
|
131
131
|
export declare function countAddressColumns(address: Address): number;
|
|
132
132
|
/**
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* @param
|
|
137
|
-
* @
|
|
138
|
-
* @
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
*
|
|
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 subrange from a spreadsheet-style A1 range (e.g., "A1:D10"),
|
|
154
|
+
* allowing skip and take semantics on both rows and columns.
|
|
155
|
+
*
|
|
156
|
+
* Supports negative values for `skipRows` and `skipCols` to count from the end.
|
|
157
|
+
* Supports negative values for `takeRows` and `takeCols` to exclude from the end after skipping.
|
|
158
|
+
*
|
|
159
|
+
* @param address - The original range in A1 notation (e.g., "A1:D10").
|
|
160
|
+
* @param skipRows - Number of rows to skip. If negative, skips that many rows from the end. Default is 0.
|
|
161
|
+
* @param takeRows - Number of rows to take after skipping. If negative, excludes that many rows from the end of the remaining rows. Default is Infinity.
|
|
162
|
+
* @param skipCols - Number of columns to skip. If negative, skips that many columns from the end. Default is 0.
|
|
163
|
+
* @param takeCols - Number of columns to take after skipping. If negative, excludes that many columns from the end of the remaining columns. Default is Infinity.
|
|
164
|
+
* @returns A new A1-style range representing the sliced subrange (e.g., "B2:C5").
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* subaddress("A1:D10", -1, 1); // Last row: "A10:D10"
|
|
168
|
+
* subaddress("A1:D10", -2, 1); // Second last row: "A9:D9"
|
|
169
|
+
* subaddress("A1:D10", 0, -1); // All but last row: "A1:D9"
|
|
170
|
+
* subaddress("A1:D10", 0, Infinity, -2, 1); // Second last column: "C1:C10"
|
|
171
|
+
*/
|
|
172
|
+
export declare function subAddress(address: Address, skipRows?: number, takeRows?: number, skipCols?: number, takeCols?: number): Address;
|
|
173
|
+
/**
|
|
174
|
+
* Extracts a subrange from a WorkbookRangeRef using skip/take semantics.
|
|
143
175
|
* @param rangeRef Range reference to extract the sub-range from.
|
|
144
|
-
* @param
|
|
145
|
-
* @param
|
|
176
|
+
* @param skipRows Number of rows to skip. If negative, skips from the end. Default 0.
|
|
177
|
+
* @param takeRows Number of rows to take after skipping. If negative, excludes from the end. Default Infinity.
|
|
178
|
+
* @param skipCols Number of columns to skip. If negative, skips from the end. Default 0.
|
|
179
|
+
* @param takeCols Number of columns to take after skipping. If negative, excludes from the end. Default Infinity.
|
|
146
180
|
* @returns Extracted sub-range reference.
|
|
147
181
|
* @throws InvalidArgumentError if the requested rows or columns exceed the available range.
|
|
148
182
|
*/
|
|
149
|
-
export declare function subrange(rangeRef: WorkbookRangeRef,
|
|
183
|
+
export declare function subrange(rangeRef: WorkbookRangeRef, skipRows?: number, takeRows?: number, skipCols?: number, takeCols?: number): WorkbookRangeRef;
|
|
150
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,W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
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,56 +258,129 @@ export function countAddressColumns(address) {
|
|
|
254
258
|
return columnAddressToOffset(components.endColumn) - columnAddressToOffset(components.startColumn) + 1;
|
|
255
259
|
}
|
|
256
260
|
/**
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
* @param
|
|
261
|
-
* @
|
|
262
|
-
* @
|
|
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")
|
|
263
278
|
*/
|
|
264
|
-
export function
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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 subrange from a spreadsheet-style A1 range (e.g., "A1:D10"),
|
|
320
|
+
* allowing skip and take semantics on both rows and columns.
|
|
321
|
+
*
|
|
322
|
+
* Supports negative values for `skipRows` and `skipCols` to count from the end.
|
|
323
|
+
* Supports negative values for `takeRows` and `takeCols` to exclude from the end after skipping.
|
|
324
|
+
*
|
|
325
|
+
* @param address - The original range in A1 notation (e.g., "A1:D10").
|
|
326
|
+
* @param skipRows - Number of rows to skip. If negative, skips that many rows from the end. Default is 0.
|
|
327
|
+
* @param takeRows - Number of rows to take after skipping. If negative, excludes that many rows from the end of the remaining rows. Default is Infinity.
|
|
328
|
+
* @param skipCols - Number of columns to skip. If negative, skips that many columns from the end. Default is 0.
|
|
329
|
+
* @param takeCols - Number of columns to take after skipping. If negative, excludes that many columns from the end of the remaining columns. Default is Infinity.
|
|
330
|
+
* @returns A new A1-style range representing the sliced subrange (e.g., "B2:C5").
|
|
331
|
+
*
|
|
332
|
+
* @example
|
|
333
|
+
* subaddress("A1:D10", -1, 1); // Last row: "A10:D10"
|
|
334
|
+
* subaddress("A1:D10", -2, 1); // Second last row: "A9:D9"
|
|
335
|
+
* subaddress("A1:D10", 0, -1); // All but last row: "A1:D9"
|
|
336
|
+
* subaddress("A1:D10", 0, Infinity, -2, 1); // Second last column: "C1:C10"
|
|
337
|
+
*/
|
|
338
|
+
export function subAddress(address, skipRows = 0, takeRows = Number.POSITIVE_INFINITY, skipCols = 0, takeCols = Number.POSITIVE_INFINITY) {
|
|
339
|
+
const { ax, bx, ay, by } = addressToCartesian(address);
|
|
340
|
+
const [startRow, endRow] = slice(ay, by, skipRows, takeRows);
|
|
341
|
+
const [startCol, endCol] = slice(ax, bx, skipCols, takeCols);
|
|
342
|
+
if (startRow < ay || endRow > by || startRow > endRow || startCol < ax || endCol > bx || startCol > endCol) {
|
|
343
|
+
throw new InvalidArgumentError(`Requested subaddress is out of bounds: rows [${startRow + 1},${endRow + 1}], cols [${startCol + 1},${endCol + 1}] in range.`);
|
|
344
|
+
}
|
|
345
|
+
return cartesianToAddress({
|
|
346
|
+
ay: startRow,
|
|
347
|
+
by: endRow,
|
|
348
|
+
ax: startCol,
|
|
349
|
+
bx: endCol,
|
|
350
|
+
});
|
|
351
|
+
function slice(start, end, skip, take) {
|
|
352
|
+
let s = start;
|
|
353
|
+
let e = end;
|
|
354
|
+
if (skip > 0) {
|
|
355
|
+
s = start + skip;
|
|
273
356
|
}
|
|
274
|
-
else if (
|
|
275
|
-
|
|
357
|
+
else if (skip < 0) {
|
|
358
|
+
s = end + skip + 1;
|
|
276
359
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
const colCount = bx - ax + 1;
|
|
280
|
-
if (Math.abs(cols) > colCount) {
|
|
281
|
-
throw new InvalidArgumentError(`Requested columns (${cols}) exceed available columns (${colCount}) in range.`);
|
|
360
|
+
if (!Number.isFinite(take)) {
|
|
361
|
+
// do nothing
|
|
282
362
|
}
|
|
283
|
-
if (
|
|
284
|
-
|
|
363
|
+
else if (take >= 0) {
|
|
364
|
+
e = s + take - 1;
|
|
285
365
|
}
|
|
286
|
-
else if (
|
|
287
|
-
|
|
366
|
+
else if (take < 0) {
|
|
367
|
+
e += take;
|
|
288
368
|
}
|
|
369
|
+
return [s, e];
|
|
289
370
|
}
|
|
290
|
-
return cartesianToAddress({
|
|
291
|
-
ay,
|
|
292
|
-
by,
|
|
293
|
-
ax,
|
|
294
|
-
bx,
|
|
295
|
-
});
|
|
296
371
|
}
|
|
297
372
|
/**
|
|
298
|
-
* Extracts a
|
|
373
|
+
* Extracts a subrange from a WorkbookRangeRef using skip/take semantics.
|
|
299
374
|
* @param rangeRef Range reference to extract the sub-range from.
|
|
300
|
-
* @param
|
|
301
|
-
* @param
|
|
375
|
+
* @param skipRows Number of rows to skip. If negative, skips from the end. Default 0.
|
|
376
|
+
* @param takeRows Number of rows to take after skipping. If negative, excludes from the end. Default Infinity.
|
|
377
|
+
* @param skipCols Number of columns to skip. If negative, skips from the end. Default 0.
|
|
378
|
+
* @param takeCols Number of columns to take after skipping. If negative, excludes from the end. Default Infinity.
|
|
302
379
|
* @returns Extracted sub-range reference.
|
|
303
380
|
* @throws InvalidArgumentError if the requested rows or columns exceed the available range.
|
|
304
381
|
*/
|
|
305
|
-
export function subrange(rangeRef,
|
|
306
|
-
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);
|
|
307
384
|
return {
|
|
308
385
|
...rangeRef,
|
|
309
386
|
address,
|