File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -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 {
@@ -57,7 +58,20 @@ export class WorkBook {
57
58
const rawList = this . book . Workbook ?. Names ?? [ ] ;
58
59
return mapEntries ( rawList , ( { Ref : ref , Name : name } , { SKIP } ) => {
59
60
const matched = / ^ ' ? ( [ ^ ' ] + ) ' ? ! ( [ $ \d A - Z ] + (?: : [ $ \d A - Z ] + ) ? ) $ / . exec ( ref ) ;
60
- return matched ? [ name , this . sheet ( matched [ 1 ] ) . range ( matched [ 2 ] ) ] : SKIP ;
61
+ if ( ! matched ) {
62
+ return SKIP ;
63
+ }
64
+ const [ _ , sheetName , rangeStr ] = matched ;
65
+ try {
66
+ const range = this . sheet ( sheetName ) . range ( rangeStr ) ;
67
+ return [ name , range ] ;
68
+ } catch ( e ) {
69
+ // Skip ranges that correspond to nonexistent sheets
70
+ if ( e instanceof NotFoundException ) {
71
+ return SKIP ;
72
+ }
73
+ throw e ;
74
+ }
61
75
} ) . asRecord ;
62
76
}
63
77
}
@@ -83,7 +97,7 @@ export class Sheet {
83
97
this . workbook = this . book . book ;
84
98
this . sheet = this . workbook . Sheets [ this . name ] ;
85
99
if ( ! this . sheet ) {
86
- throw new Error ( `Cannot find ${ this . name } sheet` ) ;
100
+ throw new NotFoundException ( `Cannot find ${ this . name } sheet` ) ;
87
101
}
88
102
}
89
103
nonEnumerable ( this , 'workbook' as any , 'sheet' as any ) ;
You can’t perform that action at this time.
0 commit comments