diff --git a/components/fpspreadsheet/examples/opendocdemo/opendocwrite.lpr b/components/fpspreadsheet/examples/opendocdemo/opendocwrite.lpr index 5a3d120d4..d69e2f9d4 100644 --- a/components/fpspreadsheet/examples/opendocdemo/opendocwrite.lpr +++ b/components/fpspreadsheet/examples/opendocdemo/opendocwrite.lpr @@ -35,6 +35,7 @@ begin // Add some formatting MyWorksheet.WriteUsedFormatting(0, 0, [uffBold]); + MyWorksheet.WriteFontColor(0, 1, scRed); // Creates a new worksheet MyWorksheet := MyWorkbook.AddWorksheet('My Worksheet 2'); diff --git a/components/fpspreadsheet/fpsopendocument.pas b/components/fpspreadsheet/fpsopendocument.pas index 37547813b..f2605710d 100755 --- a/components/fpspreadsheet/fpsopendocument.pas +++ b/components/fpspreadsheet/fpsopendocument.pas @@ -125,6 +125,7 @@ type function WriteBackgroundColorStyleXMLAsString(const AFormat: TCell): String; function WriteBorderStyleXMLAsString(const AFormat: TCell): String; + function WriteFontStyleXMLAsString(const AFormat: TCell): String; function WriteHorAlignmentStyleXMLAsString(const AFormat: TCell): String; function WriteTextRotationStyleXMLAsString(const AFormat: TCell): String; function WriteVertAlignmentStyleXMLAsString(const AFormat: TCell): String; @@ -1972,6 +1973,11 @@ begin Result := Result + ' ' + LineEnding; + s := WriteFontStyleXMLAsString(FFormattingStyles[i]); + if s <> '' then + Result := Result + + ' ' + LineEnding; + // style:table-cell-properties s := WriteBorderStyleXMLAsString(FFormattingStyles[i]) + WriteBackgroundColorStyleXMLAsString(FFormattingStyles[i]) + @@ -2430,6 +2436,39 @@ begin Result := Result + 'fo:border-top="none" '; end; +function TsSpreadOpenDocWriter.WriteFontStyleXMLAsString(const AFormat: TCell): String; +var + fnt: TsFont; + defFnt: TsFont; +begin + Result := ''; + + fnt := Workbook.GetFont(AFormat.FontIndex); + defFnt := Workbook.GetFont(0); // Defaultfont + + if fnt.FontName <> defFnt.FontName then + Result := Result + Format('style:font-name="%s" ', [fnt.FontName]); + + if fnt.Size <> defFnt.Size then + Result := Result + Format('fo:font-size="%.1fpt" style:font-size-asian="%.1fpt" style:font-size-complex="%.1fpt" ', + [fnt.Size, fnt.Size, fnt.Size], FPointSeparatorSettings); + + if fssBold in fnt.Style then + Result := Result + 'fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold" '; + + if fssItalic in fnt.Style then + Result := Result + 'fo:font-style="italic" style:font-style-asian="italic" style:font-style-complex="italic" '; + + if fssUnderline in fnt.Style then + Result := Result + 'style:text-underline-style="solid" style:text-underline-width="auto" style:text-underline-color="font-color" '; + + if fssStrikeout in fnt.Style then + Result := Result + 'style:text-line-through-style="solid" '; + + if fnt.Color <> defFnt.Color then + Result := Result + Format('fo:color="%s" ', [Workbook.GetPaletteColorAsHTMLStr(fnt.Color)]); +end; + { Creates an XML string for inclusion of the horizontal alignment into the written file from the horizontal alignment setting in the format cell. Is called from WriteStyles (via WriteStylesXMLAsString). }