From e20a18fd7f3ed2c11d599aa8918ec77d07202324 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Wed, 27 Feb 2019 22:27:47 +0000 Subject: [PATCH] fpspreadsheet: Implement spreadsheet functions ROW() and COLUMN() git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6822 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../fpspreadsheet/source/common/fpsfunc.pas | 81 +++++++++---------- 1 file changed, 39 insertions(+), 42 deletions(-) diff --git a/components/fpspreadsheet/source/common/fpsfunc.pas b/components/fpspreadsheet/source/common/fpsfunc.pas index 136c181bf..aab92421c 100644 --- a/components/fpspreadsheet/source/common/fpsfunc.pas +++ b/components/fpspreadsheet/source/common/fpsfunc.pas @@ -2076,6 +2076,24 @@ end; { Builtin lookup/reference functions } {------------------------------------------------------------------------------} +procedure fpsCOLUMN(var Result: TsExpressionResult; + const Args: TsExprParameterArray); +{ COLUMN( [reference] ) + Returns the column number of a cell reference (starting at 1!) + "reference" is a reference to a cell or range of cells. + If omitted, it is assumed that the reference is the cell address in which the + COLUMN function has been entered in. } +begin + Result := ErrorResult(errArgError); + if Length(Args) = 0 then + exit; // We don't know here which cell contains the formula. + case Args[0].ResultType of + rtCell : Result := IntegerResult(Args[0].ResCol + 1); + rtCellRange: Result := IntegerResult(Args[0].ResCellRange.Col1 + 1); + else Result := ErrorResult(errWrongType); + end; +end; + procedure fpsHYPERLINK(var Result: TsExpressionResult; const Args: TsExprParameterArray); begin @@ -2211,6 +2229,24 @@ begin // If the procedure gets here, not match has been found --> return error #N/A end; +procedure fpsROW(var Result: TsExpressionResult; + const Args: TsExprParameterArray); +{ ROW( [reference] ) + Returns the row number of a cell reference (starting at 1!) + "reference" is a reference to a cell or range of cells. + If omitted, it is assumed that the reference is the cell address in which the + ROW function has been entered in. } +begin + Result := ErrorResult(errArgError); + if Length(Args) = 0 then + exit; // We don't know here which cell contains the formula. + case Args[0].ResultType of + rtCell : Result := IntegerResult(Args[0].ResRow + 1); + rtCellRange: Result := IntegerResult(Args[0].ResCellRange.Row1 + 1); + else Result := ErrorResult(errWrongType); + end; +end; + {------------------------------------------------------------------------------} { Registration } @@ -2339,8 +2375,10 @@ begin // Lookup / reference functions cat := bcLookup; + AddFunction(cat, 'COLUMN', 'I', 'r', INT_EXCEL_SHEET_FUNC_COLUMN, @fpsCOLUMN); AddFunction(cat, 'HYPERLINK', 'S', 'Ss', INT_EXCEL_SHEET_FUNC_HYPERLINK, @fpsHYPERLINK); AddFunction(cat, 'MATCH', 'I', 'SRi', INT_EXCEL_SHEET_FUNC_MATCH, @fpsMATCH); + AddFunction(cat, 'ROW', 'I', 'r', INT_EXCEL_SHEET_FUNC_ROW, @fpsROW); (* AddFunction(cat, 'COLUMN', 'I', 'R', INT_EXCEL_SHEET_FUNC_COLUMN, @fpsCOLUMN); @@ -2351,28 +2389,8 @@ end; { Lookup / reference functions } - (* -function fpsCOLUMN(Args: TsArgumentStack; NumArgs: Integer): TsArgument; -{ COLUMN( [reference] ) - Returns the column number of a cell reference (starting at 1). - "reference" is a reference to a cell or range of cells. - If omitted, it is assumed that the reference is the cell address in which the - COLUMN function has been entered in. } -var - arg: TsArgument; -begin - if NumArgs = 0 then - Result := CreateErrorArg(errArgError); - // We don't know here which cell contains the formula. - - arg := Args.Pop; - case arg.ArgumentType of - atCell : Result := CreateNumberArg(arg.Cell^.Col + 1); - atCellRange: Result := CreateNumberArg(arg.FirstCol + 1); - else Result := CreateErrorArg(errWrongType); - end; -end; +(* function fpsCOLUMNS(Args: TsArgumentStack; NumArgs: Integer): TsArgument; { COLUMNS( [reference] ) returns the number of column in a cell reference. } @@ -2388,27 +2406,6 @@ begin end; end; -function fpsROW(Args: TsArgumentStack; NumArgs: Integer): TsArgument; -{ ROW( [reference] ) - Returns the row number of a cell reference (starting at 1!) - "reference" is a reference to a cell or range of cells. - If omitted, it is assumed that the reference is the cell address in which the - ROW function has been entered in. } -var - arg: TsArgument; -begin - if NumArgs = 0 then - Result := CreateErrorArg(errArgError); - // We don't know here which cell contains the formula. - - arg := Args.Pop; - case arg.ArgumentType of - atCell : Result := CreateNumberArg(arg.Cell^.Row + 1); - atCellRange: Result := CreateNumberArg(arg.FirstRow + 1); - else Result := CreateErrorArg(errWrongType); - end; -end; - function fpsROWS(Args: TsArgumentStack; NumArgs: Integer): TsArgument; { ROWS( [reference] )