@@ -322,12 +322,11 @@ public IEnumerable<IDictionary<string, object>> Query(bool useHeaderRow, string
322
322
{
323
323
_mergeCells . MergesValues [ aR ] = cellValue ;
324
324
}
325
- else if ( _mergeCells . MergesMap . ContainsKey ( aR ) )
325
+ else if ( _mergeCells . MergesMap . TryGetValue ( aR , out var mergeKey ) )
326
326
{
327
- var mergeKey = _mergeCells . MergesMap [ aR ] ;
328
327
object mergeValue = null ;
329
- if ( _mergeCells . MergesValues . ContainsKey ( mergeKey ) )
330
- mergeValue = _mergeCells . MergesValues [ mergeKey ] ;
328
+ if ( _mergeCells . MergesValues . TryGetValue ( mergeKey , out var value ) )
329
+ mergeValue = value ;
331
330
cellValue = mergeValue ;
332
331
}
333
332
}
@@ -398,9 +397,8 @@ private void SetCellsValueAndHeaders(object cellValue, bool useHeaderRow, ref Di
398
397
}
399
398
else
400
399
{
401
- if ( headRows . ContainsKey ( columnIndex ) )
400
+ if ( headRows . TryGetValue ( columnIndex , out var key ) )
402
401
{
403
- var key = headRows [ columnIndex ] ;
404
402
cell [ key ] = cellValue ;
405
403
}
406
404
}
@@ -467,10 +465,9 @@ private void SetCellsValueAndHeaders(object cellValue, bool useHeaderRow, ref Di
467
465
{
468
466
foreach ( var alias in pInfo . ExcelColumnAliases )
469
467
{
470
- if ( headersDic . ContainsKey ( alias ) )
468
+ if ( headersDic . TryGetValue ( alias , out var columnId ) )
471
469
{
472
470
object newV = null ;
473
- var columnId = headersDic [ alias ] ;
474
471
var columnName = keys [ columnId ] ;
475
472
item . TryGetValue ( columnName , out var itemValue ) ;
476
473
@@ -490,9 +487,8 @@ private void SetCellsValueAndHeaders(object cellValue, bool useHeaderRow, ref Di
490
487
{
491
488
item . TryGetValue ( pInfo . ExcelIndexName , out itemValue ) ;
492
489
}
493
- else if ( headersDic . ContainsKey ( pInfo . ExcelColumnName ) )
490
+ else if ( headersDic . TryGetValue ( pInfo . ExcelColumnName , out var columnId ) )
494
491
{
495
- var columnId = headersDic [ pInfo . ExcelColumnName ] ;
496
492
var columnName = keys [ columnId ] ;
497
493
item . TryGetValue ( columnName , out itemValue ) ;
498
494
}
@@ -822,7 +818,7 @@ public IEnumerable<IDictionary<string, object>> QueryRange(bool useHeaderRow, st
822
818
// if sheets count > 1 need to read xl/_rels/workbook.xml.rels
823
819
var sheets = _archive . entries . Where ( w => w . FullName . StartsWith ( "xl/worksheets/sheet" , StringComparison . OrdinalIgnoreCase )
824
820
|| w . FullName . StartsWith ( "/xl/worksheets/sheet" , StringComparison . OrdinalIgnoreCase )
825
- ) ;
821
+ ) . ToList ( ) ;
826
822
ZipArchiveEntry sheetEntry = null ;
827
823
if ( sheetName != null )
828
824
{
@@ -832,7 +828,7 @@ public IEnumerable<IDictionary<string, object>> QueryRange(bool useHeaderRow, st
832
828
throw new InvalidOperationException ( "Please check sheetName/Index is correct" ) ;
833
829
sheetEntry = sheets . Single ( w => w . FullName == $ "xl/{ s . Path } " || w . FullName == $ "/xl/{ s . Path } " || w . FullName == s . Path || s . Path == $ "/{ w . FullName } ") ;
834
830
}
835
- else if ( sheets . Count ( ) > 1 )
831
+ else if ( sheets . Count > 1 )
836
832
{
837
833
SetWorkbookRels ( _archive . entries ) ;
838
834
var s = _sheetRecords [ 0 ] ;
@@ -1086,13 +1082,9 @@ public IEnumerable<IDictionary<string, object>> QueryRange(bool useHeaderRow, st
1086
1082
{
1087
1083
_mergeCells . MergesValues [ aR ] = cellValue ;
1088
1084
}
1089
- else if ( _mergeCells . MergesMap . ContainsKey ( aR ) )
1085
+ else if ( _mergeCells . MergesMap . TryGetValue ( aR , out var mergeKey ) )
1090
1086
{
1091
- var mergeKey = _mergeCells . MergesMap [ aR ] ;
1092
- object mergeValue = null ;
1093
- if ( _mergeCells . MergesValues . ContainsKey ( mergeKey ) )
1094
- mergeValue = _mergeCells . MergesValues [ mergeKey ] ;
1095
- cellValue = mergeValue ;
1087
+ _mergeCells . MergesValues . TryGetValue ( mergeKey , out cellValue ) ;
1096
1088
}
1097
1089
}
1098
1090
////2022-09-24跳过endcell结束单元格所以在的列
@@ -1194,15 +1186,16 @@ public IEnumerable<IDictionary<string, object>> QueryRange(bool useHeaderRow, st
1194
1186
{
1195
1187
foreach ( var alias in pInfo . ExcelColumnAliases )
1196
1188
{
1197
- if ( headersDic . ContainsKey ( alias ) )
1189
+ if ( headersDic . TryGetValue ( alias , out var value ) )
1198
1190
{
1199
1191
object newV = null ;
1200
- object itemValue = item [ keys [ headersDic [ alias ] ] ] ;
1192
+ object itemValue = item [ keys [ value ] ] ;
1201
1193
1202
1194
if ( itemValue == null )
1203
1195
continue ;
1204
1196
1205
- newV = TypeHelper . TypeMapping ( v , pInfo , newV , itemValue , rowIndex , startCell , configuration ) ;
1197
+ newV = TypeHelper . TypeMapping ( v , pInfo , newV , itemValue , rowIndex , startCell ,
1198
+ configuration ) ;
1206
1199
}
1207
1200
}
1208
1201
}
@@ -1213,8 +1206,8 @@ public IEnumerable<IDictionary<string, object>> QueryRange(bool useHeaderRow, st
1213
1206
object itemValue = null ;
1214
1207
if ( pInfo . ExcelIndexName != null && keys . Contains ( pInfo . ExcelIndexName ) )
1215
1208
itemValue = item [ pInfo . ExcelIndexName ] ;
1216
- else if ( headersDic . ContainsKey ( pInfo . ExcelColumnName ) )
1217
- itemValue = item [ keys [ headersDic [ pInfo . ExcelColumnName ] ] ] ;
1209
+ else if ( headersDic . TryGetValue ( pInfo . ExcelColumnName , out var value ) )
1210
+ itemValue = item [ keys [ value ] ] ;
1218
1211
1219
1212
if ( itemValue == null )
1220
1213
continue ;
0 commit comments