11using System . Collections . ObjectModel ;
2- using MiniExcelLib . Core . Helpers ;
32using MiniExcelLib . Core . OpenXml . Constants ;
43using MiniExcelLib . Core . OpenXml . Models ;
54using MiniExcelLib . Core . OpenXml . Styles ;
6- using MiniExcelLib . Core . OpenXml . Utils ;
75using MiniExcelLib . Core . OpenXml . Zip ;
8- using MiniExcelLib . Core . Reflection ;
96using MiniExcelMapper = MiniExcelLib . Core . Reflection . MiniExcelMapper ;
107using XmlReaderHelper = MiniExcelLib . Core . OpenXml . Utils . XmlReaderHelper ;
118
129namespace MiniExcelLib . Core . OpenXml ;
1310
14- internal partial class OpenXmlReader : Abstractions . IMiniExcelReader
11+ internal partial class OpenXmlReader : IMiniExcelReader
1512{
1613 private static readonly string [ ] Ns = [ Schemas . SpreadsheetmlXmlns , Schemas . SpreadsheetmlXmlStrictns ] ;
1714 private static readonly string [ ] RelationshiopNs = [ Schemas . SpreadsheetmlXmlRelationshipns , Schemas . SpreadsheetmlXmlStrictRelationshipns ] ;
@@ -22,7 +19,7 @@ internal partial class OpenXmlReader : Abstractions.IMiniExcelReader
2219 private bool _disposed ;
2320
2421 internal readonly OpenXmlZip Archive ;
25- internal IDictionary < int , string > ? SharedStrings ;
22+ internal IDictionary < int , string > SharedStrings = new Dictionary < int , string > ( ) ;
2623
2724 private OpenXmlReader ( Stream stream , IMiniExcelConfiguration ? configuration )
2825 {
@@ -217,10 +214,8 @@ await XmlReaderHelper.SkipToNextSameLevelDomAsync(reader, cancellationToken)
217214
218215 await foreach ( var row in QueryRowAsync ( reader , isFirstRow , startRowIndex , nextRowIndex ,
219216 rowIndex , startColumnIndex , endColumnIndex , maxColumnIndex ,
220- withoutCr ,
221- useHeaderRow , headRows , mergeCellsContext . MergeCells ,
222- cancellationToken )
223- . ConfigureAwait ( false ) )
217+ withoutCr , useHeaderRow , headRows , mergeCellsContext . MergeCells ,
218+ cancellationToken ) . ConfigureAwait ( false ) )
224219 {
225220 if ( isFirstRow )
226221 {
@@ -232,8 +227,7 @@ await XmlReaderHelper.SkipToNextSameLevelDomAsync(reader, cancellationToken)
232227 yield return row ;
233228 }
234229 }
235- else if ( ! await XmlReaderHelper . SkipContentAsync ( reader , cancellationToken )
236- . ConfigureAwait ( false ) )
230+ else if ( ! await XmlReaderHelper . SkipContentAsync ( reader , cancellationToken ) . ConfigureAwait ( false ) )
237231 {
238232 break ;
239233 }
@@ -385,7 +379,7 @@ private ZipArchiveEntry GetSheetEntry(string? sheetName)
385379 : CustomPropertyHelper . GetEmptyExpandoObject ( maxColumnIndex , startColumnIndex ) ;
386380 }
387381
388- private static void SetCellsValueAndHeaders ( object ? cellValue , bool useHeaderRow , Dictionary < int , string ? > headRows , bool isFirstRow , IDictionary < string , object ? > cell , int columnIndex )
382+ private static void SetCellsValueAndHeaders ( object ? cellValue , bool useHeaderRow , Dictionary < int , string > headRows , bool isFirstRow , IDictionary < string , object ? > cell , int columnIndex )
389383 {
390384 if ( ! useHeaderRow )
391385 {
@@ -411,7 +405,7 @@ private async Task SetSharedStringsAsync(CancellationToken cancellationToken = d
411405 {
412406 cancellationToken . ThrowIfCancellationRequested ( ) ;
413407
414- if ( SharedStrings is not null )
408+ if ( SharedStrings is { Count : > 0 } )
415409 return ;
416410
417411 var sharedStringsEntry = Archive . GetEntry ( "xl/sharedStrings.xml" ) ;
@@ -432,7 +426,7 @@ private async Task SetSharedStringsAsync(CancellationToken cancellationToken = d
432426 SharedStrings [ idx ++ ] = sharedString ;
433427 }
434428 }
435- else if ( SharedStrings is null )
429+ else if ( SharedStrings is { Count : 0 } )
436430 {
437431 var list = await XmlReaderHelper . GetSharedStringsAsync ( stream , cancellationToken , Ns )
438432 . CreateListAsync ( cancellationToken )
@@ -672,30 +666,29 @@ private void ConvertCellValue(string rawValue, string aT, int xfIndex, out objec
672666 {
673667 const NumberStyles style = NumberStyles . Any ;
674668 var invariantCulture = CultureInfo . InvariantCulture ;
675-
669+ value = null ;
670+
676671 switch ( aT )
677672 {
678673 case "s" :
679674 if ( int . TryParse ( rawValue , style , invariantCulture , out var sstIndex ) )
680675 {
681676 if ( sstIndex >= 0 && sstIndex < SharedStrings ? . Count )
682677 {
683- //value = Helpers.ConvertEscapeChars(_SharedStrings[sstIndex]);
684678 value = XmlHelper . DecodeString ( SharedStrings [ sstIndex ] ) ;
685- return ;
686679 }
687680 }
688- value = null ;
689- return ;
681+ break ;
690682
691683 case "inlineStr" :
692684 case "str" :
693685 //TODO: it will unbox,box
694686 var v = XmlHelper . DecodeString ( rawValue ) ;
687+ value = v ;
695688 if ( _config . EnableConvertByteArray )
696689 {
697690 //if str start with "data:image/png;base64," then convert to byte[] https://github.com/mini-software/MiniExcel/issues/318
698- if ( v is not null && v . StartsWith ( "@@@fileid@@@," , StringComparison . Ordinal ) )
691+ if ( v ? . StartsWith ( "@@@fileid@@@," , StringComparison . Ordinal ) ?? false )
699692 {
700693 var path = v [ 13 ..] ;
701694 var entry = Archive . GetEntry ( path ) ;
@@ -708,43 +701,25 @@ private void ConvertCellValue(string rawValue, string aT, int xfIndex, out objec
708701 }
709702 value = bytes ;
710703 }
711- else
712- {
713- value = v ;
714- }
715- }
716- else
717- {
718- value = v ;
719704 }
720- return ;
705+ break ;
721706
722707 case "b" :
723708 value = rawValue == "1" ;
724709 return ;
725710
726711 case "d" :
727- if ( DateTime . TryParseExact ( rawValue , "yyyy-MM-dd" , invariantCulture , DateTimeStyles . AllowLeadingWhite | DateTimeStyles . AllowTrailingWhite , out var date ) )
728- {
729- value = date ;
730- return ;
731- }
732-
733- value = rawValue ;
712+ value = DateTime . TryParseExact ( rawValue , "yyyy-MM-dd" , invariantCulture , DateTimeStyles . AllowLeadingWhite | DateTimeStyles . AllowTrailingWhite , out var date )
713+ ? date
714+ : rawValue ;
734715 return ;
735716
736717 case "e" :
737718 value = rawValue ;
738719 return ;
739720
740721 default :
741- if ( double . TryParse ( rawValue , style , invariantCulture , out var n ) )
742- {
743- value = n ;
744- return ;
745- }
746-
747- value = rawValue ;
722+ value = double . TryParse ( rawValue , style , invariantCulture , out var n ) ? n : rawValue ;
748723 return ;
749724 }
750725 }
0 commit comments