@@ -10,6 +10,7 @@ import {
10
10
utils ,
11
11
type WorkSheet ,
12
12
} from 'xlsx' ;
13
+ import { NotFoundException } from './exceptions' ;
13
14
import { CalendarDate } from './temporal' ;
14
15
15
16
export class WorkBook {
@@ -56,8 +57,22 @@ export class WorkBook {
56
57
@Once ( ) private get namedRanges ( ) : Record < string , Range > {
57
58
const rawList = this . book . Workbook ?. Names ?? [ ] ;
58
59
return mapEntries ( rawList , ( { Ref : ref , Name : name } , { SKIP } ) => {
59
- const matched = / ^ ' ? ( [ ^ ' ] + ) ' ? ! ( [ $ \d A - Z ] + (?: : [ $ \d A - Z ] + ) ? ) $ / . exec ( ref ) ;
60
- return matched ? [ name , this . sheet ( matched [ 1 ] ) . range ( matched [ 2 ] ) ] : SKIP ;
60
+ const matched =
61
+ / ^ (?: \[ \d + ] ) ? ' ? ( [ ^ ' ] + ) ' ? ! ( [ $ \d A - Z ] + (?: : [ $ \d A - Z ] + ) ? ) $ / . exec ( ref ) ;
62
+ if ( ! matched ) {
63
+ return SKIP ;
64
+ }
65
+ const [ _ , sheetName , rangeStr ] = matched ;
66
+ try {
67
+ const range = this . sheet ( sheetName ) . range ( rangeStr ) ;
68
+ return [ name , range ] ;
69
+ } catch ( e ) {
70
+ // Skip ranges that correspond to nonexistent sheets
71
+ if ( e instanceof NotFoundException ) {
72
+ return SKIP ;
73
+ }
74
+ throw e ;
75
+ }
61
76
} ) . asRecord ;
62
77
}
63
78
}
@@ -83,7 +98,7 @@ export class Sheet {
83
98
this . workbook = this . book . book ;
84
99
this . sheet = this . workbook . Sheets [ this . name ] ;
85
100
if ( ! this . sheet ) {
86
- throw new Error ( `Cannot find ${ this . name } sheet` ) ;
101
+ throw new NotFoundException ( `Cannot find ${ this . name } sheet` ) ;
87
102
}
88
103
}
89
104
nonEnumerable ( this , 'workbook' as any , 'sheet' as any ) ;
0 commit comments