You've already forked lazarus-ccr
fpspreadsheet: Add conditions above/belowAverage to conditional formatting.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7496 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -39,6 +39,14 @@ begin
|
||||
// Use the format as conditional format of A1:A6 when cells are equal to 3.
|
||||
sh.WriteConditionalCellFormat(Range(0, 0, 5, 0), cfcEqual, 3.0, fmtIdx);
|
||||
|
||||
|
||||
sh.WriteNumber(0, 2, 10.0);
|
||||
sh.WriteNumber(1, 2, 20.0);
|
||||
sh.WriteNumber(2, 2, 15.0);
|
||||
sh.WriteNumber(3, 2, 11.0);
|
||||
sh.WriteNumber(4, 2, 19.0);
|
||||
sh.WriteConditionalCellFormat(Range(0, 2, 4, 2), cfcBelowEqualAverage, fmtIdx);
|
||||
|
||||
wb.WriteToFile('test.xlsx', true);
|
||||
finally
|
||||
wb.Free;
|
||||
|
@ -18,7 +18,7 @@ type
|
||||
cfcEqual, cfcNotEqual,
|
||||
cfcGreaterThan, cfcLessThan, cfcGreaterEqual, cfcLessEqual,
|
||||
cfcBetween, cfcNotBetween,
|
||||
cfcAboveAverage, cfcBelowAverage,
|
||||
cfcAboveAverage, cfcBelowAverage, cfcAboveEqualAverage, cfcBelowEqualAverage,
|
||||
cfcBeginsWidth, cfcEndsWith,
|
||||
cfcDuplicate, cfcUnique,
|
||||
cfcContainsText, cfcNotContaisText,
|
||||
|
@ -3345,25 +3345,48 @@ const
|
||||
('equal', 'notEqual', 'greaterThan', 'lessThan', 'greaterThanOrEqual', 'lessThanOrEqual');
|
||||
OPERATOR_NAMES_2: array[cfcBetween..cfcNotBetween] of String =
|
||||
('between', 'notBetween');
|
||||
var
|
||||
fmtID: Integer;
|
||||
aveStr, stdDevStr, eqAveStr: String;
|
||||
begin
|
||||
fmtID := 0; // to do: determine dxfId !
|
||||
|
||||
case ARule.Condition of
|
||||
cfcEqual..cfcLessEqual:
|
||||
AppendToStream(AStream, Format(
|
||||
'<cfRule type="cellIs" dxfId="0" priority="%d" operator="%s">' +
|
||||
'<cfRule type="cellIs" dxfId="%d" priority="%d" operator="%s">' +
|
||||
'<formula>%s</formula>'+
|
||||
'</cfRule>', [
|
||||
APriority, OPERATOR_NAMES_1[ARule.Condition], ARule.Operand1
|
||||
fmtID, APriority, OPERATOR_NAMES_1[ARule.Condition], ARule.Operand1
|
||||
]));
|
||||
|
||||
cfcBetween, cfcNotBetween:
|
||||
AppendToStream(AStream, Format(
|
||||
'<cfRule type="cellIs" dxfId="0" priority="%d" operator="%s">' +
|
||||
'<cfRule type="cellIs" dxfId="%d" priority="%d" operator="%s">' +
|
||||
'<formula>%s</formula>'+
|
||||
'<formula>%s</formula>'+
|
||||
'</cfRule>', [
|
||||
APriority, OPERATOR_NAMES_1[ARule.Condition], ARule.Operand1, ARule.Operand2
|
||||
fmtId, APriority, OPERATOR_NAMES_1[ARule.Condition], ARule.Operand1, ARule.Operand2
|
||||
]));
|
||||
|
||||
cfcAboveAverage..cfcBelowEqualAverage:
|
||||
begin
|
||||
if (ARule.Condition in [cfcAboveAverage, cfcAboveEqualAverage]) then
|
||||
aveStr := ''
|
||||
else
|
||||
aveStr := ' aboveAverage="0"';
|
||||
if (ARule.Condition in [cfcAboveEqualAverage, cfcBelowEqualAverage]) then
|
||||
eqAveStr := ' equalAverage="1"'
|
||||
else
|
||||
eqAveStr := '';
|
||||
if (ARule.Operand1 = varNull) or (ARule.Operand1 = 0) then
|
||||
stdDevStr := ''
|
||||
else
|
||||
stdDevStr := Format(' stdDev="%d"', [ARule.Operand1]);
|
||||
AppendToStream(AStream, Format(
|
||||
'<cfRule type="aboveAverage" dxfId="%d" priority="%d"%s%s%s />',
|
||||
[fmtId, APriority, aveStr, stdDevStr, eqAveStr]));
|
||||
end;
|
||||
else
|
||||
FWorkbook.AddErrorMsg('ConditionalFormat operator not supported.');
|
||||
end;
|
||||
|
Reference in New Issue
Block a user