From 7959f698797d544a877ab9dd4cf50e1853176b71 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Tue, 18 May 2021 10:38:33 +0000 Subject: [PATCH] fpspreadsheet: Unified usage of color syntax in Excel xlsx files git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8036 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../fpspreadsheet/source/common/xlsxooxml.pas | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/components/fpspreadsheet/source/common/xlsxooxml.pas b/components/fpspreadsheet/source/common/xlsxooxml.pas index 5de93a854..898d8df24 100644 --- a/components/fpspreadsheet/source/common/xlsxooxml.pas +++ b/components/fpspreadsheet/source/common/xlsxooxml.pas @@ -485,6 +485,13 @@ const '5Quarters' // REPLACEMENT FOR is5Boxes which needs x14 ); +function ColorToExcelStr(AColor: TsColor): String; +begin + Result := ColorToHTMLColorStr(AColor, true); // --> "00rrggbb" + Result[1] := 'F'; + Result[2] := 'F'; // --> "FFrrggbb" +end; + function StrToFillStyle(s: String): TsFillStyle; var fs: TsFillStyle; @@ -596,7 +603,7 @@ end; function CF_ColorNode(AColor: TsColor): String; begin - Result := Format('', [ColorToHTMLColorStr(AColor, true)]); + Result := Format('', [ColorToExcelStr(AColor)]); end; @@ -4117,7 +4124,7 @@ procedure TsSpreadOOXMLWriter.WriteBorderList(AStream: TStream); // Border color rgb := AFormatRecord^.BorderStyles[ABorder].Color; - colorStr := ColorToHTMLColorStr(rgb, true); + colorStr := ColorToExcelStr(rgb); AppendToStream(AStream, Format( '<%s style="%s">', [ABorderName, styleName, colorStr, ABorderName] @@ -4635,11 +4642,11 @@ begin if FFillList[i]^.Background.FgColor = scTransparent then fc := 'auto="1"' else - fc := Format('rgb="%s"', [Copy(ColorToHTMLColorStr(FFillList[i]^.Background.FgColor), 2, MaxInt)]); + fc := Format('rgb="%s"', [ColorToExcelStr(FFillList[i]^.Background.FgColor)]); if FFillList[i]^.Background.BgColor = scTransparent then bc := 'auto="1"' else - bc := Format('rgb="%s"', [Copy(ColorToHTMLColorStr(FFillList[i]^.Background.BgColor), 2, MaxInt)]); + bc := Format('rgb="%s"', [ColorToExcelStr(FFillList[i]^.Background.BgColor)]); AppendToStream(AStream, ''); AppendToStream(AStream, Format( @@ -4681,7 +4688,7 @@ begin if (fssStrikeout in AFont.Style) then s := s + ''; if AFont.Color <> scBlack then - s := s + Format('', [Copy(ColorToHTMLColorStr(AFont.Color), 2, MaxInt)]); + s := s + Format('', [ColorToExcelStr(AFont.Color)]); case AFont.Position of fpSubscript : s := s + ''; fpSuperscript: s := s + ''; @@ -5128,7 +5135,7 @@ begin if s <> '' then s := ''; if sheet.TabColor <> scNotDefined then - s := s + Format('', [Copy(ColorToHTMLColorStr(sheet.TabColor), 2, MaxInt)]); + s := s + Format('', [ColorToExcelStr(sheet.TabColor)]); if s <> '' then AppendToStream(AStream, @@ -6562,7 +6569,7 @@ procedure TsSpreadOOXMLWriter.WriteDifferentialFormat(AStream: TStream; // Border color rgb := AFormatRecord^.BorderStyles[ABorder].Color; - colorStr := ColorToHTMLColorStr(rgb, true); + colorStr := ColorToExcelStr(rgb); AppendToStream(AStream, Format( '<%s style="%s">', [ABorderName, styleName, colorStr, ABorderName] @@ -6599,7 +6606,7 @@ begin AppendToStream(AStream, ''); if font.Color <> scNotDefined then begin - fc := Copy(ColorToHTMLColorStr(font.Color), 2, MaxInt); + fc := ColorToExcelStr(font.Color); AppendToStream(AStream, Format('', [fc] )); end; if fssBold in font.Style then @@ -6629,11 +6636,11 @@ begin begin pt := PATTERN_TYPES[AFormat^.Background.Style]; if AFormat^.Background.FgColor <> scTransparent then - fc := Format('rgb="%s"', [Copy(ColorToHTMLColorStr(AFormat^.Background.FgColor), 2, MaxInt)]); + fc := Format('rgb="%s"', [ColorToExcelStr(AFormat^.Background.FgColor)]); if AFormat^.Background.BgColor = scTransparent then bc := 'auto="1"' else - bc := Format('rgb="%s"', [Copy(ColorToHTMLColorStr(AFormat^.Background.BgColor), 2, MaxInt)]); + bc := Format('rgb="%s"', [ColorToExcelStr(AFormat^.Background.BgColor)]); AppendToStream(AStream, '' + Format( '', [pt]) + Format(