fpspreadsheet: Add file missing from previous commit.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7039 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2019-07-15 22:54:02 +00:00
parent 18afbfdd84
commit b7e1b3fee8

View File

@ -709,9 +709,11 @@ type
procedure ParserError(Msg: String); procedure ParserError(Msg: String);
function GetExpression: String; function GetExpression: String;
function GetLocalizedExpression(const AFormatSettings: TFormatSettings): String; virtual; function GetLocalizedExpression(const AFormatSettings: TFormatSettings): String; virtual;
function GetR1C1Expression(ACell: PCell): String;
procedure SetExpression(const AValue: String); procedure SetExpression(const AValue: String);
procedure SetLocalizedExpression(const AFormatSettings: TFormatSettings; procedure SetLocalizedExpression(const AFormatSettings: TFormatSettings;
const AValue: String); virtual; const AValue: String); virtual;
procedure SetR1C1Expression(ACell: PCell; const AValue: String);
procedure UpdateExprFormatSettings; procedure UpdateExprFormatSettings;
procedure CheckResultType(const Res: TsExpressionResult; procedure CheckResultType(const Res: TsExpressionResult;
@ -756,6 +758,8 @@ type
property ListSeparator: Char read FListSep; property ListSeparator: Char read FListSep;
property LocalizedExpression[AFormatSettings: TFormatSettings]: String property LocalizedExpression[AFormatSettings: TFormatSettings]: String
read GetLocalizedExpression write SetLocalizedExpression; read GetLocalizedExpression write SetLocalizedExpression;
property R1C1Expression[ACell: PCell]: String
read GetR1C1Expression write SetR1C1Expression;
property RPNFormula: TsRPNFormula read GetRPNFormula write SetRPNFormula; property RPNFormula: TsRPNFormula read GetRPNFormula write SetRPNFormula;
property Identifiers: TsExprIdentifierDefs read FIdentifiers write SetIdentifiers; property Identifiers: TsExprIdentifierDefs read FIdentifiers write SetIdentifiers;
property BuiltIns: TsBuiltInExprCategories read FBuiltIns write SetBuiltIns; property BuiltIns: TsBuiltInExprCategories read FBuiltIns write SetBuiltIns;
@ -1123,31 +1127,48 @@ begin
end; end;
function TsExpressionScanner.DoIdentifier: TsTokenType; function TsExpressionScanner.DoIdentifier: TsTokenType;
function IsR1C1Char(C: Char): Boolean; inline;
begin
Result := (FParser.Dialect = fdExcelR1C1) and (C in ['[', ']', '-']);
end;
var var
C: Char; C: Char;
S: String; S: String;
isQuoted: Boolean; isQuoted: Boolean;
ok: Boolean;
begin begin
C := CurrentChar; C := CurrentChar;
isQuoted := C = ''''; isQuoted := C = '''';
while ((not IsWordDelim(C)) or IsQuoted) and (C <> cNULL) do
while ((not IsWordDelim(C)) or IsQuoted or IsR1C1Char(C)) and (C <> cNULL) do
begin begin
FToken := FToken + C; FToken := FToken + C;
C := NextPos; C := NextPos;
if C = '''' then isQuoted := false; if C = '''' then isQuoted := false;
end; end;
if ParseCellRangeString(FToken, FSheet1, FSheet2, if (FParser.Dialect = fdExcelR1C1) then begin
FCellRange.Row1, FCellRange.Col1, FCellRange.Row2, FCellRange.Col2, FFlags ok := ParseCellRangeString_R1C1(FToken,
) and (C <> '(') FParser.FDestCell^.Row, FParser.FDestCell^.Col,
then FSheet1, FSheet2,
FCellRange.Row1, FCellRange.Col1, FCellRange.Row2, FCellRange.Col2,
FFlags)
end else begin
ok := ParseCellRangeString(FToken,
FSheet1, FSheet2,
FCellRange.Row1, FCellRange.Col1, FCellRange.Row2, FCellRange.Col2,
FFlags);
end;
if ok and (C <> '(') then
begin begin
Result := ttSpreadsheetAddress; Result := ttSpreadsheetAddress;
exit; exit;
end; end;
S := LowerCase(FToken); S := LowerCase(FToken);
if (S = 'true') and (C <> '(') then if (S = 'true') and (C <> '(') then
Result := ttTrue Result := ttTrue
else if (S = 'false') and (C <> '(') then else if (S = 'false') and (C <> '(') then
@ -1356,7 +1377,13 @@ function TsExpressionScanner.IsWordDelim(C: Char): Boolean;
begin begin
Result := (C in WordDelimiters) or (C = FParser.ListSeparator); Result := (C in WordDelimiters) or (C = FParser.ListSeparator);
end; end;
(*
function TsExpressionScanner.IsWordDelimR1C1(C: Char): boolean;
begin
Result := not (C in (['[', ']'] + Digits)
Result := (C in (WordDelimiters + ['[', ']'])) or (C = FParser.ListSeparator);
end;
*)
function TsExpressionScanner.NextPos: Char; function TsExpressionScanner.NextPos: Char;
begin begin
Inc(FPos); Inc(FPos);
@ -1577,6 +1604,23 @@ begin
Result := Res.ResString; Result := Res.ResString;
end; end;
{ Returns the expression in R1C1 notation.
ACell is the cell to which the expression is assumed to be relative. }
function TsExpressionParser.GetR1C1Expression(ACell: PCell): String;
var
oldDialect: TsFormulaDialect;
begin
oldDialect := FDialect;
try
FDialect := fdExcelR1C1;
PrepareCopyMode(ACell, ACell);
Result := Expression;
finally
PrepareCopyMode(nil, nil);
FDialect := oldDialect;
end;
end;
function TsExpressionParser.GetRPNFormula: TsRPNFormula; function TsExpressionParser.GetRPNFormula: TsRPNFormula;
begin begin
Result := CreateRPNFormula(FExprNode.AsRPNItem(nil), true); Result := CreateRPNFormula(FExprNode.AsRPNItem(nil), true);
@ -2020,6 +2064,23 @@ begin
FIdentifiers.Assign(AValue) FIdentifiers.Assign(AValue)
end; end;
{ Parses an expression in which cell references are given in Excel's R1C1 notation
ACell is the cell to which the created expression will be relative. }
procedure TsExpressionParser.SetR1C1Expression(ACell: PCell; const AValue: String);
var
oldDialect: TsFormulaDialect;
begin
oldDialect := FDialect;
try
FDialect := fdExcelR1C1;
PrepareCopyMode(ACell, ACell);
Expression := AValue;
finally
FDialect := oldDialect;
PrepareCopyMode(nil, nil);
end;
end;
procedure TsExpressionParser.SetRPNFormula(const AFormula: TsRPNFormula); procedure TsExpressionParser.SetRPNFormula(const AFormula: TsRPNFormula);
procedure CreateNodeFromRPN(var ANode: TsExprNode; var AIndex: Integer); procedure CreateNodeFromRPN(var ANode: TsExprNode; var AIndex: Integer);