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
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]));
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);
// 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
Result := StringResult(UTF8Trim(ArgToString(Args[0])));
end;
@ -862,6 +877,9 @@ begin
else
if TryStrToFloat(s, x, ExprFormatSettings) then
Result := FloatResult(x)
else
if TryStrToDateTime(s, x) then
Result := FloatResult(x)
else
Result := ErrorResult(errWrongType);
end;
@ -1630,6 +1648,7 @@ begin
AddFunction(cat, 'REPT', 'S', 'SI', INT_EXCEL_SHEET_FUNC_REPT, @fpsREPT);
AddFunction(cat, 'RIGHT', 'S', 'Si', INT_EXCEL_SHEET_FUNC_RIGHT, @fpsRIGHT);
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, 'UPPER', 'S', 'S', INT_EXCEL_SHEET_FUNC_UPPER, @fpsUPPER);
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
we always have valid sheet names independent of the format.
@param AName Name to be checked. If the input name is already
used AName will be modified such that the sheet
name is unique.
@param AName Name to be checked.
@param ReplaceDuplicateName If there exists already a sheet name equal to
AName then a number is added to AName such that
the name is unique.