From fbe85d7e44a944eef116219a961721ecafcd6737 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Fri, 26 Jun 2020 11:37:21 +0000 Subject: [PATCH] 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 --- .../demo_conditional_formatting.pas | 10 ++++++++++ components/fpspreadsheet/source/common/xlsxooxml.pas | 12 +++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) 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 067050c53..8fd4d1f61 100644 --- a/components/fpspreadsheet/examples/other/conditional_formatting/demo_conditional_formatting.pas +++ b/components/fpspreadsheet/examples/other/conditional_formatting/demo_conditional_formatting.pas @@ -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 diff --git a/components/fpspreadsheet/source/common/xlsxooxml.pas b/components/fpspreadsheet/source/common/xlsxooxml.pas index c8903d7c3..8181fd210 100644 --- a/components/fpspreadsheet/source/common/xlsxooxml.pas +++ b/components/fpspreadsheet/source/common/xlsxooxml.pas @@ -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( + '', [typeStr, dxfID, APriority])); + end; else FWorkbook.AddErrorMsg('ConditionalFormat operator not supported.'); end;