@@ -341,13 +341,23 @@ private void GetSharedStrings()
341
341
if ( xr . LocalName == "t" && xr . NodeType == XmlNodeType . Element )
342
342
{
343
343
var text = ConvertUtil . ExcelDecodeString ( xr . ReadElementContentAsString ( ) ) ;
344
- _sharedStringsListNew . Add ( new SharedStringTextItem ( ) { Text = text , Position = index } ) ;
345
- if ( ! _sharedStringsLookup . ContainsKey ( text ) )
344
+ if ( xr . Name == "r" && xr . NodeType == XmlNodeType . Element )
346
345
{
347
- _sharedStringsLookup . Add ( text , index ++ ) ;
348
- }
349
- }
350
- else if ( xr . LocalName == "r" && xr . NodeType == XmlNodeType . Element )
346
+ var item = new SharedStringRichTextItem ( ) { RichText = new ExcelRichTextCollection ( xr , this ) , Position = index ++ } ;
347
+ item . RichText . Insert ( 0 , text ) ;
348
+ _sharedStringsListNew . Add ( item ) ;
349
+ text = item . RichText . GetXML ( ) ;
350
+ }
351
+ else
352
+ {
353
+ _sharedStringsListNew . Add ( new SharedStringTextItem ( ) { Text = text , Position = index } ) ;
354
+ if ( ! _sharedStringsLookup . ContainsKey ( text ) )
355
+ {
356
+ _sharedStringsLookup . Add ( text , index ++ ) ;
357
+ }
358
+ }
359
+ }
360
+ if ( xr . LocalName == "r" && xr . NodeType == XmlNodeType . Element )
351
361
{
352
362
var item = new SharedStringRichTextItem ( ) { RichText = new ExcelRichTextCollection ( xr , this ) , Position = index ++ } ;
353
363
_sharedStringsListNew . Add ( item ) ;
@@ -734,34 +744,37 @@ public ExcelThreadedCommentPersonCollection ThreadedCommentPersons
734
744
}
735
745
}
736
746
/// <summary>
737
- /// Max font width for the workbook
738
- /// <remarks>This method uses GDI. If you use Azure or another environment that does not support GDI, you have to set this value manually if you don't use the standard Calibri font</remarks>
747
+ /// Max font width for the workbook, used in the calculation of column widths.
748
+ /// <remarks>This property uses the static <see cref="FontSize.FontWidths"></see> dictionary to get the max font width /> </remarks>
739
749
/// </summary>
740
750
public decimal MaxFontWidth
741
751
{
742
752
get
743
753
{
744
- var ix = Styles . GetNormalStyleIndex ( ) ;
745
- if ( ix >= 0 )
754
+ if ( _standardFontWidth == decimal . MinValue )
746
755
{
747
- var font = Styles . NamedStyles [ ix ] . Style . Font ;
748
- if ( font . Index == int . MinValue ) font . Index = 0 ;
749
- if ( _standardFontWidth == decimal . MinValue || _fontID != font . Id )
756
+ var ix = Styles . GetNormalStyleIndex ( ) ;
757
+ if ( ix >= 0 )
750
758
{
751
- try
759
+ var font = Styles . NamedStyles [ ix ] . Style . Font ;
760
+ if ( font . Index == int . MinValue ) font . Index = 0 ;
761
+ if ( _standardFontWidth == decimal . MinValue || _fontID != font . Id )
752
762
{
753
- _standardFontWidth = FontSize . GetWidthPixels ( font . Name , font . Size ) ;
754
- _fontID = Styles . NamedStyles [ ix ] . Style . Font . Id ;
755
- }
756
- catch //Error, Font missing and Calibri removed in dictionary
757
- {
758
- _standardFontWidth = ( int ) ( font . Size * ( 2D / 3D ) ) ; //Aprox for Calibri.
763
+ try
764
+ {
765
+ _standardFontWidth = FontSize . GetWidthPixels ( font . Name , font . Size ) ;
766
+ _fontID = Styles . NamedStyles [ ix ] . Style . Font . Id ;
767
+ }
768
+ catch //Error, Font missing and Calibri removed in dictionary
769
+ {
770
+ _standardFontWidth = ( int ) ( font . Size * ( 2D / 3D ) ) ; //Aprox for Calibri.
771
+ }
759
772
}
760
773
}
761
- }
762
- else
763
- {
764
- _standardFontWidth = 7 ; //Calibri 11
774
+ else
775
+ {
776
+ _standardFontWidth = 7 ; //Calibri 11
777
+ }
765
778
}
766
779
return _standardFontWidth ;
767
780
}
@@ -1957,13 +1970,14 @@ internal ExcelTable GetTable(string name)
1957
1970
1958
1971
internal void ClearDefaultHeightsAndWidths ( )
1959
1972
{
1960
- foreach ( var ws in Worksheets )
1973
+ _standardFontWidth = decimal . MinValue ;
1974
+ foreach ( var ws in Worksheets )
1961
1975
{
1962
1976
if ( ws . IsChartSheet == false )
1963
1977
{
1964
1978
if ( ws . CustomHeight == false )
1965
1979
{
1966
- ws . _defaultRowHeight = double . NaN ;
1980
+ ws . _defaultRowHeight = double . NaN ;
1967
1981
}
1968
1982
}
1969
1983
}
0 commit comments