fpspreadsheet: Fix writing of conditional fonts to xlsx.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8035 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2021-05-18 10:24:52 +00:00
parent 1641eba327
commit 639385a707
2 changed files with 17 additions and 8 deletions

View File

@@ -76,8 +76,9 @@ begin
// conditional format #2: equal to text constant
inc(row);
sh.WriteText(row, 0, 'equal to text "abc"');
sh.WriteText(row, 1, 'background green');
sh.WriteText(row, 1, 'background green, bold text');
fmt.SetBackgroundColor(scGreen);
fmt.SetFont(2); // Font #2 in fps is bold, by default.
fmtIdx := wb.AddCellFormat(fmt);
// Write conditional format
sh.WriteConditionalCellFormat(Range(row, 2, row, lastCol), cfcEqual, 'abc', fmtIdx);

View File

@@ -4668,8 +4668,10 @@ var
s: String;
begin
s := '';
s := s + Format('<sz val="%g" />', [AFont.Size], FPointSeparatorSettings);
s := s + Format('<%s val="%s" />', [NAME_TAG[UseInStyleNode], AFont.FontName]);
if AFont.Size > 0 then
s := s + Format('<sz val="%g" />', [AFont.Size], FPointSeparatorSettings);
if AFont.FontName <> '' then
s := s + Format('<%s val="%s" />', [NAME_TAG[UseInStyleNode], AFont.FontName]);
if (fssBold in AFont.Style) then
s := s + '<b />';
if (fssItalic in AFont.Style) then
@@ -6572,7 +6574,7 @@ procedure TsSpreadOOXMLWriter.WriteDifferentialFormat(AStream: TStream;
var
pt, bc, fc, diag: string;
// font: TsFont;
font: TsFont;
nfp: TsNumFormatParams;
nfs: String;
nfi: Integer;
@@ -6585,24 +6587,30 @@ begin
// TODO: Fix font handling: although correct in syntax something seems to be missing...
if (uffFont in AFormat^.UsedFormattingFields) then
begin
(*
AFormat^.UsedFormattingFields := AFormat^.UsedFormattingfields - [uffFont]; // trying to make the file readable...
FWorkbook.AddErrorMsg('Writing conditional font not supported by XLSX writer.');
{
*)
font := TsWorkbook(FWorkbook).GetFont(AFormat^.FontIndex);
if font <> nil then
begin
AppendToStream(AStream, '<font>');
if font.Color <> scNotDefined then
begin
fc := Copy(ColorToHTMLColorStr(font.Color), 2, MaxInt);
AppendToStream(AStream, Format('<color rgb="%s" />', [fc] ));
end;
if fssBold in font.Style then
AppendToStream(AStream, '<b />');
AppendToStream(AStream, '<b />');
if fssItalic in font.Style then
AppendToStream(AStream, '<i />');
AppendToStream(AStream, '<i />');
if fssStrikeout in font.Style then
AppendToStream(AStream, '<strike />');
AppendToStream(AStream, '<strike />');
// Font name, font size, and style underline not supported
AppendToStream(AStream, '</font>');
end;
}
end;
{ number format }