fpspreadsheet: xlsx writer supports conditional formatting for duplicate/unique values.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7500 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-06-26 11:37:21 +00:00
parent 9a71231010
commit fbe85d7e44
2 changed files with 21 additions and 1 deletions

View File

@ -85,6 +85,16 @@ begin
fmtIdx := wb.AddCellFormat(fmt);
sh.WriteConditionalCellFormat(Range(0, 0, 100, 100), cfcContainsErrors, fmtIdx);
{ ------ 6th conditional format: unique/duplicate values ----------------- }
sh.WriteNumber(0, 1, 1.0);
sh.WriteNumber(1, 1, 99.0);
InitFormatRecord(fmt);
fmt.SetBackgroundColor(scSilver);
sh.WriteConditionalCellFormat(Range(0, 0, 1, 1), cfcUnique, wb.AddCellFormat(fmt));
fmt.SetBackgroundColor(scGreen);
sh.WriteConditionalCellFormat(Range(0, 0, 1, 1), cfcDuplicate, wb.AddCellFormat(fmt));
{ ------ Save workbook to file-------------------------------------------- }
wb.WriteToFile('test.xlsx', true);
finally

View File

@ -3360,7 +3360,7 @@ const
var
i: Integer;
dxfID: Integer;
aveStr, stdDevStr, eqAveStr, opStr: String;
typeStr, aveStr, stdDevStr, eqAveStr, opStr: String;
firstCellOfRange: String;
begin
dxfID := -1;
@ -3424,6 +3424,16 @@ begin
opStr
]));
end;
cfcDuplicate, cfcUnique:
begin
if ARule.Condition = cfcUnique then
typeStr := 'uniqueValues'
else
typeStr := 'duplicateValues';
AppendToStream(AStream, Format(
'<cfRule type="%s" dxfId="%d" priority="%d" />', [typeStr, dxfID, APriority]));
end;
else
FWorkbook.AddErrorMsg('ConditionalFormat operator not supported.');
end;