From de42ac007268686919697b605d770b24f4cdca47 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sat, 20 Jul 2019 21:33:59 +0000 Subject: [PATCH] fpspreadsheet: Fix application of cell format to a cell range by TsNumberFormatAction. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7064 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../source/visual/fpsactions.pas | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/components/fpspreadsheet/source/visual/fpsactions.pas b/components/fpspreadsheet/source/visual/fpsactions.pas index d00bef052..f7f95ee1e 100644 --- a/components/fpspreadsheet/source/visual/fpsactions.pas +++ b/components/fpspreadsheet/source/visual/fpsactions.pas @@ -273,6 +273,7 @@ type private FNumberFormat: TsNumberFormat; FNumberFormatStr: string; + FCustomNumberFormatStr: String; FOnGetNumFormatStr: TsNumFormatStrEvent; procedure SetNumberFormat(AValue: TsNumberFormat); procedure SetNumberFormatStr(AValue: String); @@ -282,6 +283,7 @@ type procedure UpdateCaptionAndHint; public constructor Create(AOwner: TComponent); override; + procedure ExecuteTarget(Target: TObject); override; published property NumberFormat: TsNumberFormat read FNumberFormat write SetNumberFormat default nfGeneral; @@ -1221,7 +1223,7 @@ begin Caption := rsNumberFormatCaption_General; Hint := rsNumberFormatHint_General; GroupIndex := 1411141258; // Date/time when this code was written - AutoCheck := true; + //AutoCheck := true; end; procedure TsNumberFormatAction.ApplyFormatToCell(ACell: PCell); @@ -1231,16 +1233,11 @@ var begin if Checked then begin - if (FNumberFormat = nfCustom) and Assigned(FOnGetNumFormatStr) then - begin - Worksheet.ReadNumFormat(ACell, nf, nfstr); - FOnGetNumFormatStr(self, Workbook, nfstr); - nf := nfCustom; - end else - begin - nf := FNumberFormat; + nf := FNumberFormat; + if FNumberFormat = nfCustom then + nfstr := FCustomNumberFormatStr + else nfstr := FNumberFormatStr; - end; end else begin nf := nfGeneral; @@ -1252,6 +1249,23 @@ begin Worksheet.WriteNumberFormat(ACell, nf, nfstr); end; +procedure TsNumberFormatAction.ExecuteTarget(Target: TObject); +var + nf: TsNumberFormat; + nfstr: String; +begin + if (FNumberFormat = nfCustom) and Assigned(FOnGetNumFormatStr) then + begin + Worksheet.ReadNumFormat(ActiveCell, nf, nfstr); + FOnGetNumFormatStr(self, Workbook, nfstr); + FCustomNumberFormatStr := nfstr; + Checked := true; + end else + Checked := not Checked; + + inherited; +end; + procedure TsNumberFormatAction.ExtractFromCell(ACell: PCell); var nf: TsNumberFormat;