From 2abce47ffb1c0c098895f43921ae66aa8cb7f11e Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Mon, 18 Jan 2016 16:09:55 +0000 Subject: [PATCH] fpspreadsheet: Add property NumberFormats to TsWorksheetGrid. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4433 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../fpspreadsheet/fpspreadsheetgrid.pas | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/components/fpspreadsheet/fpspreadsheetgrid.pas b/components/fpspreadsheet/fpspreadsheetgrid.pas index b9ccd7d7b..46103e3af 100644 --- a/components/fpspreadsheet/fpspreadsheetgrid.pas +++ b/components/fpspreadsheet/fpspreadsheetgrid.pas @@ -101,6 +101,7 @@ type function GetHorAlignments(ARect: TGridRect): TsHorAlignment; function GetHyperlink(ACol, ARow: Integer): String; function GetNumberFormat(ACol, ARow: Integer): String; + function GetNumberFormats(ARect: TGridRect): String; function GetShowGridLines: Boolean; function GetShowHeaders: Boolean; function GetTextRotation(ACol, ARow: Integer): TsTextRotation; @@ -137,6 +138,7 @@ type procedure SetHorAlignments(ARect: TGridRect; AValue: TsHorAlignment); procedure SetHyperlink(ACol, ARow: Integer; AValue: String); procedure SetNumberFormat(ACol, ARow: Integer; AValue: String); + procedure SetNumberFormats(ARect: TGridRect; AValue: String); procedure SetReadFormulas(AValue: Boolean); procedure SetShowGridLines(AValue: Boolean); procedure SetShowHeaders(AValue: Boolean); @@ -371,6 +373,10 @@ type {@@ Number format (as Excel string) to be applied to cell at column ACol and row ARow. } property NumberFormat[ACol, ARow: Integer]: String read GetNumberFormat write SetNumberFormat; + {@@ Number format (as Excel string) to be applied to all cells within the + range of column/row indexes defined by the rectangle. } + property NumberFormats[ARect: TGridRect]: String + read GetNumberFormats write SetNumberFormats; {@@ Rotation of the text in the cell at column ACol and row ARow. } property TextRotation[ACol, ARow: Integer]: TsTextRotation read GetTextRotation write SetTextRotation; @@ -4550,6 +4556,22 @@ begin end; end; +function TsCustomWorksheetGrid.GetNumberFormats(ARect: TGridRect): String; +var + c, r: Integer; + nfs: String; +begin + nfs := GetNumberformat(ARect.Left, ARect.Top); + for r := ARect.Left to ARect.Right do + for c := ARect.Top to ARect.Bottom do + if nfs <> GetNumberFormat(c, r) then + begin + Result := ''; + exit; + end; + Result := nfs; +end; + function TsCustomWorksheetGrid.GetShowGridLines: Boolean; begin Result := (Options * [goHorzLine, goVertLine] <> []); @@ -5002,6 +5024,20 @@ begin Worksheet.WriteNumberFormat(GetWorksheetRow(ARow), GetWorksheetCol(ACol), nfCustom, AValue); end; +procedure TsCustomWorksheetGrid.SetNumberFormats(ARect: TGridRect; AValue: String); +var + c,r: Integer; +begin + BeginUpdate; + try + for c := ARect.Left to ARect.Right do + for r := ARect.Top to ARect.Bottom do + SetNumberFormat(c, r, AValue); + finally + EndUpdate; + end; +end; + procedure TsCustomWorksheetGrid.SetReadFormulas(AValue: Boolean); begin FReadFormulas := AValue;