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 fda7367fa..c9f61297e 100644 --- a/components/fpspreadsheet/examples/other/conditional_formatting/demo_conditional_formatting.pas +++ b/components/fpspreadsheet/examples/other/conditional_formatting/demo_conditional_formatting.pas @@ -15,6 +15,8 @@ begin wb := TsWorkbook.Create; try sh := wb.AddWorksheet('test'); + + { ------ 1st conditional format ------------------------------------------ } sh.WriteNumber(0, 0, 1.0); sh.WriteNumber(1, 0, 2.0); sh.WriteNumber(2, 0, 3.0); @@ -40,13 +42,20 @@ begin sh.WriteConditionalCellFormat(Range(0, 0, 5, 0), cfcEqual, 3.0, fmtIdx); + { ------- 2nd conditional format ----------------------------------------- } 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); + + InitFormatRecord(fmt); + fmt.SetBackgroundColor(scRed); + fmtIdx := wb.AddCellFormat(fmt); + sh.WriteConditionalCellFormat(Range(0, 2, 4, 2), cfcBelowEqualAverage, fmtIdx); + { ------ Save workbook to file-------------------------------------------- } wb.WriteToFile('test.xlsx', true); finally wb.Free; diff --git a/components/fpspreadsheet/source/common/xlsxooxml.pas b/components/fpspreadsheet/source/common/xlsxooxml.pas index b085c33da..c5f709d40 100644 --- a/components/fpspreadsheet/source/common/xlsxooxml.pas +++ b/components/fpspreadsheet/source/common/xlsxooxml.pas @@ -3346,10 +3346,17 @@ const OPERATOR_NAMES_2: array[cfcBetween..cfcNotBetween] of String = ('between', 'notBetween'); var + i: Integer; fmtID: Integer; aveStr, stdDevStr, eqAveStr: String; begin - fmtID := 0; // to do: determine dxfId ! + fmtID := -1; + for i := 0 to High(FDifferentialFormatIndexList) do + if FDifferentialFormatIndexList[i] = ARule.FormatIndex then + begin + fmtID := i; + break; + end; case ARule.Condition of cfcEqual..cfcLessEqual: