diff --git a/components/fpspreadsheet/source/common/xlsbiff2.pas b/components/fpspreadsheet/source/common/xlsbiff2.pas index ba836fb52..03fbc221f 100644 --- a/components/fpspreadsheet/source/common/xlsbiff2.pas +++ b/components/fpspreadsheet/source/common/xlsbiff2.pas @@ -513,6 +513,7 @@ var lOptions: Word; Len: Byte; lFontName: UTF8String; + isDefaultFont: Boolean; begin FFont := TsFont.Create; @@ -534,8 +535,13 @@ begin AStream.ReadBuffer(lFontName[1], Len); FFont.FontName := lFontName; + isDefaultFont := FFontList.Count = 0; + { Add font to internal font list } FFontList.Add(FFont); + + if isDefaultFont then + Workbook.SetDefaultFont(FFont.FontName, FFont.Size); end; procedure TsSpreadBIFF2Reader.ReadFONTCOLOR(AStream: TStream); diff --git a/components/fpspreadsheet/source/common/xlsbiff5.pas b/components/fpspreadsheet/source/common/xlsbiff5.pas index b5ce0b012..553fbbe80 100644 --- a/components/fpspreadsheet/source/common/xlsbiff5.pas +++ b/components/fpspreadsheet/source/common/xlsbiff5.pas @@ -961,6 +961,7 @@ var Len: Byte; fontname: ansistring; font: TsFont; + isDefaultFont: Boolean; begin font := TsFont.Create; @@ -1025,6 +1026,8 @@ begin AStream.ReadBuffer(fontname[1], Len); font.FontName := ConvertEncoding(fontname, FCodePage, encodingUTF8); + isDefaultFont := FFontList.Count = 0; + { Add font to internal font list. Will be copied to workbook's font list later as the font index in the internal list may be different from the index in the workbook's list. } @@ -1032,6 +1035,9 @@ begin { Excel does not have zero-based font #4! } if FFontList.Count = 4 then FFontList.Add(nil); + + if isDefaultFont then + FWorkbook.SetDefaultFont(font.FontName, font.Size); end; // Read the FORMAT record for formatting numerical data diff --git a/components/fpspreadsheet/source/common/xlsbiff8.pas b/components/fpspreadsheet/source/common/xlsbiff8.pas index b760568f4..0d21794e2 100644 --- a/components/fpspreadsheet/source/common/xlsbiff8.pas +++ b/components/fpspreadsheet/source/common/xlsbiff8.pas @@ -1792,6 +1792,7 @@ var Len: Byte; font: TsFont; rtParams: TsRichTextParams; + isDefaultFont: Boolean; begin font := TsFont.Create; @@ -1849,6 +1850,8 @@ begin Len := AStream.ReadByte(); font.FontName := ReadString(AStream, Len, rtParams); // rtParams is not used here. + isDefaultFont := FFontList.Count = 0; + { Add font to internal font list; will be transferred to workbook later because the font index in the internal list (= index in file) is not the same as the index the font will have in the workbook's fontlist! } @@ -1856,6 +1859,9 @@ begin { Excel does not have zero-based font #4! } if FFontList.Count = 4 then FFontList.Add(nil); + + if isDefaultFont then + Workbook.SetDefaultFont(font.FontName, font.Size); end; {@@ ---------------------------------------------------------------------------- diff --git a/components/fpspreadsheet/source/common/xlsxooxml.pas b/components/fpspreadsheet/source/common/xlsxooxml.pas index 45a7e0469..7de70fd26 100644 --- a/components/fpspreadsheet/source/common/xlsxooxml.pas +++ b/components/fpspreadsheet/source/common/xlsxooxml.pas @@ -1392,7 +1392,10 @@ var nodename: String; s: String; acceptDuplicates: Boolean; + isDefaultFont: Boolean; begin + isDefaultFont := FFontList.Count = 0; + fnt := Workbook.GetDefaultFont; if fnt <> nil then begin @@ -1497,6 +1500,9 @@ begin fnt.Position := fntPos; Result := FFontList.Add(fnt); + + if isDefaultFont then + Workbook.SetDefaultFont(fnt.FontName, fnt.Size); end; procedure TsSpreadOOXMLReader.ReadFonts(ANode: TDOMNode);