fpspreadsheet: Avoid writing duplicate conditional formatting styles to "styles.xml" of ods file.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7511 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2020-07-01 16:08:11 +00:00
parent 7f80fea142
commit efa8009d96
2 changed files with 24 additions and 15 deletions

View File

@ -18,12 +18,12 @@ begin
wb := TsWorkbook.Create;
try
sh := wb.AddWorksheet('test');
sh.WriteDefaultColWidth(20, suMillimeters);
sh.WriteDefaultColWidth(15, suMillimeters);
sh.WriteText(0, 0, 'Condition');
sh.WriteColWidth(0, 60, suMillimeters);
sh.WriteText(0, 1, 'Format');
sh.WriteColWidth(1, 70, suMillimeters);
sh.WriteColWidth(1, 90, suMillimeters);
sh.WriteText(0, 2, 'Test values');
row := 2;
@ -49,7 +49,7 @@ begin
sh.WriteFormula(i, 18, '=1.0/1.0');
end;
lastCol := 18;
(*
// conditional format #1: equal to number constant
sh.WriteText(row, 0, 'equal to constant 5');
sh.WriteText(row, 1, 'background yellow');
@ -255,11 +255,11 @@ begin
fmt.SetBackgroundColor(scRed);
fmtIdx := wb.AddCellFormat(fmt);
sh.WriteConditionalCellFormat(Range(row, 2, row, lastCol), cfcContainsErrors, fmtIdx);
*)
// conditional format #6: no errors
inc(row);
sh.WriteText(row, 0, 'no errors');
sh.WriteText(row, 1, 'background red');
sh.WriteText(row, 1, 'background yellow, font "Courier New"/red/bold/14');
fmt.SetBackgroundColor(scYellow);
fmt.SetFont(wb.AddFont('Courier New', 14, [fssBold], scRed));
fmtIdx := wb.AddCellFormat(fmt);

View File

@ -6022,24 +6022,33 @@ var
fmtIndex: Integer;
cf_rule: TsCFRule;
stylename: String;
L: TStrings;
begin
book := TsWorkbook(FWorkbook);
nCF := book.GetNumConditionalFormats;
for i := 0 to nCF-1 do
begin
CF := book.GetConditionalFormat(i);
for j := 0 to CF.RulesCount-1 do
L := TStringList.Create;
try
for i := 0 to nCF-1 do
begin
cf_Rule := CF.Rules[j];
if cf_Rule is TsCFCellRule then
CF := book.GetConditionalFormat(i);
for j := 0 to CF.RulesCount-1 do
begin
fmtIndex := TsCFCellRule(cf_Rule).FormatIndex;
fmt := book.GetCellFormat(TsCFCellRule(cf_Rule).FormatIndex);
stylename := Format('conditional_%d', [fmtIndex]);
WriteConditionalStyle(AStream, stylename, fmt);
cf_Rule := CF.Rules[j];
if cf_Rule is TsCFCellRule then
begin
fmtIndex := TsCFCellRule(cf_Rule).FormatIndex;
fmt := book.GetCellFormat(TsCFCellRule(cf_Rule).FormatIndex);
stylename := Format('conditional_%d', [fmtIndex]);
if L.IndexOf(styleName) = -1 then begin
WriteConditionalStyle(AStream, stylename, fmt);
L.Add(styleName);
end;
end;
end;
end;
finally
L.Free;
end;
end;