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:
parent
7f80fea142
commit
efa8009d96
@ -18,12 +18,12 @@ begin
|
|||||||
wb := TsWorkbook.Create;
|
wb := TsWorkbook.Create;
|
||||||
try
|
try
|
||||||
sh := wb.AddWorksheet('test');
|
sh := wb.AddWorksheet('test');
|
||||||
sh.WriteDefaultColWidth(20, suMillimeters);
|
sh.WriteDefaultColWidth(15, suMillimeters);
|
||||||
|
|
||||||
sh.WriteText(0, 0, 'Condition');
|
sh.WriteText(0, 0, 'Condition');
|
||||||
sh.WriteColWidth(0, 60, suMillimeters);
|
sh.WriteColWidth(0, 60, suMillimeters);
|
||||||
sh.WriteText(0, 1, 'Format');
|
sh.WriteText(0, 1, 'Format');
|
||||||
sh.WriteColWidth(1, 70, suMillimeters);
|
sh.WriteColWidth(1, 90, suMillimeters);
|
||||||
sh.WriteText(0, 2, 'Test values');
|
sh.WriteText(0, 2, 'Test values');
|
||||||
|
|
||||||
row := 2;
|
row := 2;
|
||||||
@ -49,7 +49,7 @@ begin
|
|||||||
sh.WriteFormula(i, 18, '=1.0/1.0');
|
sh.WriteFormula(i, 18, '=1.0/1.0');
|
||||||
end;
|
end;
|
||||||
lastCol := 18;
|
lastCol := 18;
|
||||||
(*
|
|
||||||
// conditional format #1: equal to number constant
|
// conditional format #1: equal to number constant
|
||||||
sh.WriteText(row, 0, 'equal to constant 5');
|
sh.WriteText(row, 0, 'equal to constant 5');
|
||||||
sh.WriteText(row, 1, 'background yellow');
|
sh.WriteText(row, 1, 'background yellow');
|
||||||
@ -255,11 +255,11 @@ begin
|
|||||||
fmt.SetBackgroundColor(scRed);
|
fmt.SetBackgroundColor(scRed);
|
||||||
fmtIdx := wb.AddCellFormat(fmt);
|
fmtIdx := wb.AddCellFormat(fmt);
|
||||||
sh.WriteConditionalCellFormat(Range(row, 2, row, lastCol), cfcContainsErrors, fmtIdx);
|
sh.WriteConditionalCellFormat(Range(row, 2, row, lastCol), cfcContainsErrors, fmtIdx);
|
||||||
*)
|
|
||||||
// conditional format #6: no errors
|
// conditional format #6: no errors
|
||||||
inc(row);
|
inc(row);
|
||||||
sh.WriteText(row, 0, 'no errors');
|
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.SetBackgroundColor(scYellow);
|
||||||
fmt.SetFont(wb.AddFont('Courier New', 14, [fssBold], scRed));
|
fmt.SetFont(wb.AddFont('Courier New', 14, [fssBold], scRed));
|
||||||
fmtIdx := wb.AddCellFormat(fmt);
|
fmtIdx := wb.AddCellFormat(fmt);
|
||||||
|
@ -6022,24 +6022,33 @@ var
|
|||||||
fmtIndex: Integer;
|
fmtIndex: Integer;
|
||||||
cf_rule: TsCFRule;
|
cf_rule: TsCFRule;
|
||||||
stylename: String;
|
stylename: String;
|
||||||
|
L: TStrings;
|
||||||
begin
|
begin
|
||||||
book := TsWorkbook(FWorkbook);
|
book := TsWorkbook(FWorkbook);
|
||||||
nCF := book.GetNumConditionalFormats;
|
nCF := book.GetNumConditionalFormats;
|
||||||
|
|
||||||
for i := 0 to nCF-1 do
|
L := TStringList.Create;
|
||||||
begin
|
try
|
||||||
CF := book.GetConditionalFormat(i);
|
for i := 0 to nCF-1 do
|
||||||
for j := 0 to CF.RulesCount-1 do
|
|
||||||
begin
|
begin
|
||||||
cf_Rule := CF.Rules[j];
|
CF := book.GetConditionalFormat(i);
|
||||||
if cf_Rule is TsCFCellRule then
|
for j := 0 to CF.RulesCount-1 do
|
||||||
begin
|
begin
|
||||||
fmtIndex := TsCFCellRule(cf_Rule).FormatIndex;
|
cf_Rule := CF.Rules[j];
|
||||||
fmt := book.GetCellFormat(TsCFCellRule(cf_Rule).FormatIndex);
|
if cf_Rule is TsCFCellRule then
|
||||||
stylename := Format('conditional_%d', [fmtIndex]);
|
begin
|
||||||
WriteConditionalStyle(AStream, stylename, fmt);
|
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;
|
||||||
end;
|
end;
|
||||||
|
finally
|
||||||
|
L.Free;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user