diff --git a/components/fpspreadsheet/examples/other/conditional_formatting/demo_conditional_formatting.pas b/components/fpspreadsheet/examples/other/conditional_formatting/demo_conditional_formatting.pas index b5fb03865..fda7367fa 100644 --- a/components/fpspreadsheet/examples/other/conditional_formatting/demo_conditional_formatting.pas +++ b/components/fpspreadsheet/examples/other/conditional_formatting/demo_conditional_formatting.pas @@ -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; diff --git a/components/fpspreadsheet/source/common/fpsconditionalformat.pas b/components/fpspreadsheet/source/common/fpsconditionalformat.pas index 050aa2aca..430b37cdc 100644 --- a/components/fpspreadsheet/source/common/fpsconditionalformat.pas +++ b/components/fpspreadsheet/source/common/fpsconditionalformat.pas @@ -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, diff --git a/components/fpspreadsheet/source/common/xlsxooxml.pas b/components/fpspreadsheet/source/common/xlsxooxml.pas index e4476ff0c..b085c33da 100644 --- a/components/fpspreadsheet/source/common/xlsxooxml.pas +++ b/components/fpspreadsheet/source/common/xlsxooxml.pas @@ -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( - '' + + '' + '%s'+ '', [ - APriority, OPERATOR_NAMES_1[ARule.Condition], ARule.Operand1 + fmtID, APriority, OPERATOR_NAMES_1[ARule.Condition], ARule.Operand1 ])); cfcBetween, cfcNotBetween: AppendToStream(AStream, Format( - '' + + '' + '%s'+ '%s'+ '', [ - 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( + '', + [fmtId, APriority, aveStr, stdDevStr, eqAveStr])); + end; else FWorkbook.AddErrorMsg('ConditionalFormat operator not supported.'); end;