fpspreadsheet: Add function TEXT() and fix function VALUE() to make the provided test files of the test suite readable by fpspreadsheet.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4018 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2015-03-12 13:11:33 +00:00
parent 26fef957ec
commit 1ded103b39
2 changed files with 22 additions and 5 deletions

View File

@ -18,7 +18,7 @@ implementation
uses uses
Math, lazutf8, StrUtils, DateUtils, Math, lazutf8, StrUtils, DateUtils,
xlsconst, {%H-}fpsPatches, fpsUtils, fpsexprparser; xlsconst, {%H-}fpsPatches, fpsUtils, fpsnumformat, fpsexprparser;
{------------------------------------------------------------------------------} {------------------------------------------------------------------------------}
@ -833,9 +833,24 @@ begin
Result := StringResult(UTF8StringReplace(s, sOld, sNew, [rfReplaceAll])); Result := StringResult(UTF8StringReplace(s, sOld, sNew, [rfReplaceAll]));
end; end;
procedure fpsTEXT(var Result: TsExpressionResult; const Args: TsExprParameterArray);
// TEXT( value, format )
// Returns a value converted to text with a specified format.
var
fmt: String;
value: double;
begin
value := ArgToFloat(Args[0]);
fmt := ArgToString(Args[1]);
if IsDateTimeFormat(fmt) then
Result := StringResult(FormatDateTime(fmt, value))
else
Result := StringResult(Format(fmt, [value]));
end;
procedure fpsTRIM(var Result: TsExpressionResult; const Args: TsExprParameterArray); procedure fpsTRIM(var Result: TsExpressionResult; const Args: TsExprParameterArray);
// TRIM( text ) // TRIM( text )
// returns a text value with the leading and trailing spaces removed // Returns a text value with the leading and trailing spaces removed
begin begin
Result := StringResult(UTF8Trim(ArgToString(Args[0]))); Result := StringResult(UTF8Trim(ArgToString(Args[0])));
end; end;
@ -862,6 +877,9 @@ begin
else else
if TryStrToFloat(s, x, ExprFormatSettings) then if TryStrToFloat(s, x, ExprFormatSettings) then
Result := FloatResult(x) Result := FloatResult(x)
else
if TryStrToDateTime(s, x) then
Result := FloatResult(x)
else else
Result := ErrorResult(errWrongType); Result := ErrorResult(errWrongType);
end; end;
@ -1630,6 +1648,7 @@ begin
AddFunction(cat, 'REPT', 'S', 'SI', INT_EXCEL_SHEET_FUNC_REPT, @fpsREPT); AddFunction(cat, 'REPT', 'S', 'SI', INT_EXCEL_SHEET_FUNC_REPT, @fpsREPT);
AddFunction(cat, 'RIGHT', 'S', 'Si', INT_EXCEL_SHEET_FUNC_RIGHT, @fpsRIGHT); AddFunction(cat, 'RIGHT', 'S', 'Si', INT_EXCEL_SHEET_FUNC_RIGHT, @fpsRIGHT);
AddFunction(cat, 'SUBSTITUTE','S', 'SSSi', INT_EXCEL_SHEET_FUNC_SUBSTITUTE, @fpsSUBSTITUTE); AddFunction(cat, 'SUBSTITUTE','S', 'SSSi', INT_EXCEL_SHEET_FUNC_SUBSTITUTE, @fpsSUBSTITUTE);
AddFunction(cat, 'TEXT', 'S', '?S', INT_EXCEL_SHEET_FUNC_TEXT, @fpsTEXT);
AddFunction(cat, 'TRIM', 'S', 'S', INT_EXCEL_SHEET_FUNC_TRIM, @fpsTRIM); AddFunction(cat, 'TRIM', 'S', 'S', INT_EXCEL_SHEET_FUNC_TRIM, @fpsTRIM);
AddFunction(cat, 'UPPER', 'S', 'S', INT_EXCEL_SHEET_FUNC_UPPER, @fpsUPPER); AddFunction(cat, 'UPPER', 'S', 'S', INT_EXCEL_SHEET_FUNC_UPPER, @fpsUPPER);
AddFunction(cat, 'VALUE', 'F', 'S', INT_EXCEL_SHEET_FUNC_VALUE, @fpsVALUE); AddFunction(cat, 'VALUE', 'F', 'S', INT_EXCEL_SHEET_FUNC_VALUE, @fpsVALUE);

View File

@ -6771,9 +6771,7 @@ end;
(ODS seems to be a bit less restrictive, but if we follow Excel's convention (ODS seems to be a bit less restrictive, but if we follow Excel's convention
we always have valid sheet names independent of the format. we always have valid sheet names independent of the format.
@param AName Name to be checked. If the input name is already @param AName Name to be checked.
used AName will be modified such that the sheet
name is unique.
@param ReplaceDuplicateName If there exists already a sheet name equal to @param ReplaceDuplicateName If there exists already a sheet name equal to
AName then a number is added to AName such that AName then a number is added to AName such that
the name is unique. the name is unique.