diff --git a/components/fpspreadsheet/fpsopendocument.pas b/components/fpspreadsheet/fpsopendocument.pas index ca9537630..fcba23689 100755 --- a/components/fpspreadsheet/fpsopendocument.pas +++ b/components/fpspreadsheet/fpsopendocument.pas @@ -67,6 +67,8 @@ type procedure WriteStyles; procedure WriteContent(AData: TsWorkbook); procedure WriteWorksheet(CurSheet: TsWorksheet); + // Routines to write parts of those files + function WriteStylesXMLAsString: string; public { General writing methods } procedure WriteStringToFile(AString, AFileName: string); @@ -368,7 +370,12 @@ end; procedure TsSpreadOpenDocWriter.WriteContent(AData: TsWorkbook); var i: Integer; + lStylesCode: string; begin + ListAllFormattingStyles(AData); + + lStylesCode := WriteStylesXMLAsString(); + FContent := XML_HEADER + LineEnding + '' + LineEnding + ' ' + LineEnding + ' ' + LineEnding + - ' ' + LineEnding + - ' ' + LineEnding + - ' ' + LineEnding + + // Automatically Generated Styles + lStylesCode + ' ' + LineEnding + // Body @@ -474,6 +480,58 @@ begin ' ' + LineEnding; end; +function TsSpreadOpenDocWriter.WriteStylesXMLAsString: string; +var + i: Integer; +begin + Result := ''; + + for i := 0 to Length(FFormattingStyles) - 1 do + begin + // Start and Name + Result := Result + + ' ' + LineEnding; + + // Fields + if uffBold in FFormattingStyles[i].UsedFormattingFields then + Result := Result + + ' ' + LineEnding; + + if (uffBorder in FFormattingStyles[i].UsedFormattingFields) or + (uffBackgroundColor in FFormattingStyles[i].UsedFormattingFields) then + begin + Result := Result + ' ' + LineEnding; + end; + + // End + Result := Result + + ' ' + LineEnding; + end; +end; + { Writes a string to a file. Helper convenience method. } @@ -563,9 +621,13 @@ procedure TsSpreadOpenDocWriter.WriteLabel(AStream: TStream; const ARow, ACol: Word; const AValue: string; ACell: PCell); var lStyle: string = ''; + lIndex: Integer; begin - if uffBold in ACell^.UsedFormattingFields then - lStyle := ' table:style-name="bold" '; + if ACell^.UsedFormattingFields <> [] then + begin + lIndex := FindFormattingInList(ACell); + lStyle := ' table:style-name="ce' + IntToStr(lIndex) + '" '; + end; // The row should already be the correct one FContent := FContent + diff --git a/components/fpspreadsheet/fpspreadsheet.pas b/components/fpspreadsheet/fpspreadsheet.pas index 562e6ceef..8cb80271c 100755 --- a/components/fpspreadsheet/fpspreadsheet.pas +++ b/components/fpspreadsheet/fpspreadsheet.pas @@ -284,6 +284,7 @@ type procedure ListAllFormattingStylesCallback(ACell: PCell; AStream: TStream); procedure ListAllFormattingStyles(AData: TsWorkbook); function ExpandFormula(AFormula: TsFormula): TsExpandedFormula; + function FPSColorToHexString(AColor: TsColor): string; { General writing methods } procedure WriteCellCallback(ACell: PCell; AStream: TStream); procedure WriteCellsToStream(AStream: TStream; ACells: TAVLTree); @@ -1107,6 +1108,31 @@ begin end; end; +function TsCustomSpreadWriter.FPSColorToHexString(AColor: TsColor): string; +begin + case AColor of + scBlack: Result := '000000'; + scWhite: Result := 'FFFFFF'; + scRed: Result := 'FF0000'; + scGREEN: Result := '00FF00'; + scBLUE: Result := '0000FF'; + scYELLOW: Result := 'FFFF00'; + scMAGENTA: Result := 'FF00FF'; + scCYAN: Result := '00FFFF'; + scDarkRed: Result := '800000'; + scDarkGreen:Result := '008000'; + scDarkBlue: Result := '000080'; + scOLIVE: Result := '808000'; + scPURPLE: Result := '800080'; + scTEAL: Result := '008080'; + scSilver: Result := 'C0C0C0'; + scGrey: Result := '808080'; + // + scGrey10pct:Result := 'E6E6E6'; + scGrey20pct:Result := 'CCCCCC'; + end; +end; + {@@ Helper function for the spreadsheet writers.