ClosedXML.Parser
Binary operations that can occur in the formula.
&
+
-
*
/
^
>=
<=
<
>
!=
=
,
SPACE
:
A visitor that generates the identical formula for the parsed formula based on passed arguments.
CopyVisitor doesn't make any judgements if passed arguments have been modified. It just makes
a newly allocated copy based on passed values.
Convert between A1 and R1C1 style formulas.
Convert a formula in A1 form to the R1C1 form.
Formula text.
The row origin of R1C1, from 1 to 1048576.
The column origin of R1C1, from 1 to 16384.
Formula converted to R1C1.
The formula is not parseable.
Convert a formula in R1C1 form to the A1 form.
Formula text in R1C1.
The row origin of R1C1, from 1 to 1048576.
The column origin of R1C1, from 1 to 16384.
Formula converted to A1.
The formula is not parseable.
Modify the formula using the passed .
Original formula in A1 style.
Row number of formula.
Column number of formula.
Visitor to transform the formula.
Modify the formula using the passed .
Original formula in A1 style.
Name of the sheet where is the formula.
Row number of formula.
Column number of formula.
Visitor to transform the formula.
A parser of Excel formulas, with main purpose of creating an abstract syntax tree.
An implementation is a recursive descent parser, based on the ANTLR grammar.
Type of a scalar value used across expressions.
Type of a node used in the AST.
A context of the parsing. It's passed to every factory method and can contain global info that doesn't belong individual nodes.
Is parser in A1 mode (true) or R1C1 mode (false)?
Parse a formula using A1 semantic for references.
Formula text that will be parsed.
Context that is going to be passed to every method of the .
Factory to create nodes of AST tree.
If the formula doesn't satisfy the grammar.
Parse a formula using R1C1 semantic for references.
Formula text that will be parsed.
Context that is going to be passed to every method of the .
Factory to create nodes of AST tree.
If the formula doesn't satisfy the grammar.
Parser for two rules unified into a single method.
prefix_atom_expression
: (PLUS | MINUS) prefix_atom_expression
| atom_expression
;
arg_prefix_atom_expression
: (PLUS | MINUS) arg_prefix_atom_expression
| arg_atom_expression
;
Does the method represent prefix_atom_expression (false) or arg_prefix_atom_expression (true)
Is the expression of the node a reference expression?
ref_implicit_expression
: INTERSECT ref_implicit_expression
| ref_intersection_expression
;
Parser of the following node.
ref_spill_expression
: ref_atom_expression SPILL?
;
a1_reference
: A1_CELL
| A1_CELL COLON A1_CELL
| A1_SPAN_REFERENCE
;
A factory used to create an AST through .
Sheet names are in most cases strings, while most other texts are ReadOnlySpan<char>.
The reason is that sheet name is always used as-is and in some methods is null, while
other parameters might be processed. E.g. errors are likely to be transformed to enum, function name
might need conversion from text IFS to _xlfn.IFS and so on.
Type of a scalar value used across expressions.
Type of a node used in the AST.
A context of the parsing. It's passed to every factory method and can contain global info that doesn't belong individual nodes.
Create a logical value for an array item.
User supplied context for parsing a tree that is an argument of a parsing method.
Symbol range of the logical token in the formula.
The logical value of an array.
Create a numerical value for an array item.
User supplied context for parsing a tree that is an argument of a parsing method.
Symbol range of the number token in the formula.
The numeric value of an array. Never NaN or Infinity.
Create a text value for an array item.
User supplied context for parsing a tree that is an argument of a parsing method.
Symbol range of the text token in the formula.
The text. The characters of text are already unescaped.
Create an error for an array item.
User supplied context for parsing a tree that is an argument of a parsing method.
Symbol range of the error token in the formula.
The error text, string with # until the end of an error. No whitespace, converted to upper case, no matter the input.
Create an array for scalar values.
User supplied context for parsing a tree that is an argument of a parsing method.
Symbol range of the array symbol in the formula.
Number of rows of an array. At least 1.
Number of column of an array. At least 1.
Elements of an array, row by row. The number of elements is *.
Create a blank node. In most cases, a blank argument of a function, e.g. IF(TRUE,,).
User supplied context for parsing a tree that is an argument of a parsing method.
Range in a formula that contains the blank.
Create a node with a logical value.
User supplied context for parsing a tree that is an argument of a parsing method.
Range in a formula that contains the logical.
The logical value that will be represented by the node.
Create a node with an error value.
Sheet related ref errors (e.g. Sheet!REF! or #REF!$A$4) are also use this node. In that case,
the contains whole section used to create the error, but
contains normalized #REF! error.
User supplied context for parsing a tree that is an argument of a parsing method.
Range in a formula that contains the error.
The error text, string with # until the end of an error. No whitespace. In upper case format.
Create a node with an error value.
User supplied context for parsing a tree that is an argument of a parsing method.
Range in a formula that contains the number.
The numeric value of an array. Never NaN or Infinity.
Create a node with a text value.
User supplied context for parsing a tree that is an argument of a parsing method.
Range in a formula that contains the text.
The text. The characters of text are already unescaped.
Create a node for a reference to cells without a worksheet.
User supplied context for parsing a tree that is an argument of a parsing method.
Range in a formula that contains the reference.
The referenced area.
Create a node for a reference in a specific sheet.
User supplied context for parsing a tree that is an argument of a parsing method.
Range in a formula that contains the sheet reference.
Name of a sheet (unescaped) of the .
Area in the sheet.
Create a node that processes a bang reference in a formula (e.g "Branch:" & !$C$5). Bang reference should
- Be used only in defined names.
- Always be absolute (name doesn't have an anchor).
User supplied context for parsing a tree that is an argument of a parsing method.
Range in a formula that contains the bang reference.
Area in the sheet.
Create a node for a 3D reference.
User supplied context for parsing a tree that is an argument of a parsing method.
Range in a formula that contains the 3D reference.
First sheet of 3D reference.
Last sheet of 3D reference.
Area in all sheets of 3D reference.
Create a node for a reference to cells of a specific sheet in a different worksheet.
User supplied context for parsing a tree that is an argument of a parsing method.
Range in a formula that contains the external sheet reference.
Id of an external workbook. The actual path to the file is in workbook part, externalReferences tag.
Name of a sheet (unescaped) of the .
Area the external sheet.
Create a node for a 3D reference in a different workbook.
User supplied context for parsing a tree that is an argument of a parsing method.
Range in a formula that contains the external 3D reference.
Id of an external workbook. The actual path to the file is in workbook part, externalReferences tag.
First sheet of 3D reference.
Last sheet of 3D reference.
Area in all sheets of 3D reference.
Create a node for a function.
User supplied context for parsing a tree that is an argument of a parsing method.
Range in a formula that contains the function including arguments.
Name of a function.
Nodes of argument values.
Create a node for a function on a sheet. Might happen for VBA.
User supplied context for parsing a tree that is an argument of a parsing method.
Name of a sheet.
Name of a function.
Nodes of argument values.
Create a node for a sheet-scoped function from an external workbook.
User supplied context for parsing a tree that is an argument of a parsing method.
Id of an external workbook. The actual path to the file is in workbook part, externalReferences tag.
Name of a sheet in external workbook.
Name of the function.
Nodes of argument values.
Create a node for a function from an external workbook.
User supplied context for parsing a tree that is an argument of a parsing method.
Range in a formula that contains the function including arguments.
Id of an external workbook. The actual path to the file is in workbook part, externalReferences tag.
Name of the function.
Nodes of argument values.
Create a cell function. It references another function that should likely contain a LAMBDA value.
Cell functions are not yet supported by Excel, but are part of a grammar.
User supplied context for parsing a tree that is an argument of a parsing method.
Range in a formula that contains the cell function.
A reference to a cell with a LAMBDA. Is a single cell.
Arguments to pass to a LAMBDA.
Create a node to represent a structure reference without a table to a range of columns.
Such reference is only allowed in the table (e.g. total formulas).
User supplied context for parsing a tree that is an argument of a parsing method.
Range in a formula that contains the structure reference.
A portion of a table that should be considered.
The first column of a range. Null, if whole table. If only one column, same as .
The last column of a range. Null, if whole table.If only one column, same as .
Create a node to represent a structure reference to a table.
User supplied context for parsing a tree that is an argument of a parsing method.
Range in a formula that contains the structure reference.
A name of a table.
A portion of a table that should be considered.
The first column of a range. Null, if whole table. If only one column, same as .
The last column of a range. Null, if whole table.If only one column, same as .
Create a node to represent a structure reference to a table in some other workbook.
User supplied context for parsing a tree that is an argument of a parsing method.
Range in a formula that contains the structure reference.
Id of external workbook.
A name of a table.
A portion of a table that should be considered.
The first column of a range. Null, if whole table. If only one column, same as .
The last column of a range. Null, if whole table.If only one column, same as .
Create a node that should evaluate to a value of a name defined in a workbook.
Name can be any formula, though in most cases, it is a cell reference. Also note that
names can be global (usable in a whole workbook) or local (only for one worksheet).
User supplied context for parsing a tree that is an argument of a parsing method.
Range in a formula that contains the name.
The defined name.
Create a node that should evaluate to a value of a name defined in a worksheet.
Name can be any formula, though in most cases, it is a cell reference. Also note that
names can be global (usable in a whole workbook) or local (only for one worksheet).
User supplied context for parsing a tree that is an argument of a parsing method.
Range in a formula that contains the name.
Name of a sheet, unescaped.
The defined name.
Create a node that processes a bang name in a formula (e.g "Branch:" & !Data). Bang reference should
be used only in defined names.
TODO: This method is not yet implemented, just added so I don't have to deal with API breakage.
User supplied context for parsing a tree that is an argument of a parsing method.
Range in a formula that contains the bang reference.
The defined name.
Create a node that should evaluate to a value of a defined name in a different workbook.
User supplied context for parsing a tree that is an argument of a parsing method.
Id of an external workbook. The actual path to the file is in workbook part, externalReferences tag.
Name from a workbook. It can be defined name or a name of a table.
Create a node that should evaluate to a value of a defined name in a worksheet of a different workbook.
Name can be any formula, though in most cases, it is a cell reference. Also note that
names can be global (usable in a whole workbook) or local (only for one worksheet).
User supplied context for parsing a tree that is an argument of a parsing method.
Range in a formula that contains the name.
Id of an external workbook. The actual path to the file is in workbook part, externalReferences tag.
Name of a sheet in the external workbook, unescaped.
The defined name.
Create a node that performs a binary operation on values from another nodes.
User supplied context for parsing a tree that is an argument of a parsing method.
Range in a formula that contains the binary operation.
Binary operation.
Node that should be evaluated for left argument of a binary operation.
Node that should be evaluated for right argument of a binary operation.
Create a node that performs an unary operation on a value from another node.
User supplied context for parsing a tree that is an argument of a parsing method.
Unary operation.
Node that should be evaluated for a value.
This factory method is called for nested expression in braces ((1+2)/4). The problem isn't that
it would be evaluated incorrectly, but it is to preserve braces during A1 to R1C1 transformation.
User supplied context for parsing a tree that is an argument of a parsing method.
The node representing expression in braces.
Simplest implementation returns the same node and avoids extra nodes.
A context for modifications of a formula through .
Create a context for modifying formulas.
Create a context for modifying formulas.
The original formula without any modifications.
Name of the current sheet.
Absolute row number in a sheet.
Absolute column number in a sheet.
Should references in formula be A1?
A class for checking whether an identifier in a formula requires quotes or
can can be used without quotes. This is an Excel custom behavior, unrelated
to the unicode standard. The grammar defines a behavior, but that is not
how Excel behaves. Microsoft likely made a selection based on each
individual language without any connection to Unicode codepoint categories
(e.g. it likely marked quote-like symbols from each language as requiring
quotes). Data used in the methods were collected directly from Excel using
AutoHotKey script.
A bitmask indicating if the sheet name with first codepoint should be quoted.
Generated by `Generate_sheet_quotation_data`. BitArray is fast and takes up only
few KiB.
A bitmask indicating if the sheet name with next such codepoint should be quoted.
Generated by `Generate_sheet_quotation_data`. BitArray is fast and takes up only
few KiB.
Character not allowed in a sheet name, even quoted one.
Should the name be quoted?
Sheet names can't contain *,/,:,?,[,\,
], but method doesn't check for that. Also, it can't start with ',
though it can be non-first character.
The name. Must be at least 1 char long.
True, if the sheet name should be quoted in formula.
If name is empty.
Is the name of a sheet valid?
Name of the sheet.
Indicates an error during parsing. In most cases, unexpected token.
Due to frequency of an area in formulas, the grammar has a token that represents
an area in a sheet. This is the DTO from parser to engine. Two corners make an area
for A1 notation, but not for R1C1 (has several edge cases).
First reference. First in terms of position in formula, not position
in sheet.
Second reference. Second in terms of position in formula, not position
in sheet. If area was specified using only one cell, the value is
same as .
Semantic style of reference.
Is area a row span (e.g. $5:7 in A1 or R[7], R7:R[9])?
Is area a col span (e.g. $C:Z in A1 or C[7], C7:C[9])?
Create a reference symbol using the two (e.g.
A1:B2) or two columns (e.g. A:D) or two rows (e.g.
7:8).
Create an area for a single reference.
Create a new area from a single .
Row axis type of a reference.
Row position.
Column axis type of a reference.
Column position.
Semantic of the reference.
Create a new area from a single row/column intersection.
row.
column.
Semantic of the reference.
Render area in A1 notation. The content must be a valid content
from A1 token. If both references are same, only one is converted
to display string.
Render area in R1C1 notation. The content must be a valid content
from R1C1 token. If both references are same, only one is converted
to display string.
Convert A1 reference to R1C1.
Assumes reference is in A1.
Convert R1C1 reference to A1.
Assumes reference is in R1C1.
Get reference in A1 notation.
Assumes reference is in A1.
Get reference in R1C1 notation.
Assumes reference is in R1C1.
The type of content stored in a row or column number of a reference.
Axis is relative. E.g. A5 for A1, R[-3] for R1C1.
Keep 0, so default RowCol is A1.
Units are absolute. E.g. $A$5 for A1, R8C5 for R1C1.
The reference axis (row or column) is not specified for reference.
Generally, it means whole axis is used. If the type is ,
the value is ignored, but should be 0.
Examples:
- A:B in A1 doesn't specify row.
- R2 in R1C1 doesn't specify column.
A utility class that parses various types of references.
Try to parse as a sheet reference (Sheet!A5) or a local
reference (A1). If the is a local reference, the output
value of the is null.
Unlike the or ,
this method can parse both sheet reference or local reference.
Text to parse.
The unescaped name of a sheet for sheet reference, null for local reference.
The parsed reference area.
true if parsing was a success, false otherwise.
Parses area reference in A1 form. The possibilities are
- Cell (e.g. F8).
- Area (e.g. B2:$D7).
- Colspan (e.g. $D:$G).
- Rowspan (e.g. 14:$15).
Doesn't allow any whitespaces or extra values inside.
Text to parse.
Parsed area.
true if parsing was a success, false otherwise.
Parses area reference in A1 form. The possibilities are
- Cell (e.g. F8).
- Area (e.g. B2:$D7).
- Colspan (e.g. $D:$G).
- Rowspan (e.g. 14:$15).
Doesn't allow any whitespaces or extra values inside.
Invalid input.
Try to parse a A1 reference that has a sheet (e.g. 'Data values'!A$1:F10).
If contains only reference without a sheet or anything
else (e.g. A1), return false.
The method doesn't accept
- Sheet names, e.g. Sheet!name.
- External sheet references, e.g. [1]Sheet!A1.
- Sheet errors, e.g. Sheet5!$REF!.
Text to parse.
Name of the sheet, unescaped (e.g. the sheetName will contain Jane's for 'Jane''s'!A1).
Parsed reference.
true if parsing was a success, false otherwise.
Try to parse as a name (e.g. Name) or a sheet name
(Sheet!Name). If the is only a name, the output value of the
is null.
Text to parse.
The unescaped name of a sheet for sheet name, null for a name.
The parsed name.
true if parsing was a success, false otherwise.
Try to parse a text as a sheet name (e.g. Sheet!Name). Doesn't accept pure name
without sheet (e.g. name).
Text to parse.
Parsed sheet name, unescaped.
Parsed defined name.
true if parsing was a success, false otherwise.
Style of referencing areas in a worksheet.
The reference ( or )
uses A1 semantic. Even relative references start from
[1,1], but relative references move when cells move.
The reference ( or )
uses R1C1 semantic. Relative references are relative to
the cell that contains the reference, not [1,1].
It's designed to allow modifications of references, e.g. renaming, moving references
and so on. Just inherit it and override one of virtual Modify* methods.
An extension to modify sheet name, e.g. rename.
The transformation context.
Original sheet name.
New sheet name. If null, it indicates sheet has been deleted and should be replaced with #REF!
Modify reference to a cell.
The origin of formula.
Original name of a table.
Modified name of a table or null if #REF!.
An extension to modify name of a function. Doesn't modify the sheet/external functions.
The transformation context.
Original name of function.
New name of a function.
Modify reference to a cell. This method is called for every place where is a ref and is
mostly intended to change reference style.
The origin of formula.
Area reference.
Modified reference or null if #REF!.
Modify reference to a cell function.
The transformation context.
Original cell containing function.
Modified reference or null if #REF!.
Get all tokens for a formula. Use A1 semantic. If there is an error, add token with an error symbol at the end or EOF token at the end.
Formula to parse.
Get all tokens for a formula. Use R1C1 semantic. If there is an error, add token with an error symbol at the end or EOF token at the end.
Formula to parse.
A class required by a Rolex tool. Never used.
One endpoint of a reference defined by row and column axis. It can be
-
A single cell that is an intersection of row and a column
-
An entire row, e.g. A:B or R5:R10.
-
An entire column, e.g. 7:14 or C7:C10.
The content of values and thus their interpretation depends on the
reference style, e.g. column 14 with
can indicate R[14] or X14 for A1
style.
Not all combinations are valid and the content of the reference corresponds
to a valid token in expected reference style (e.g. in R1C1, R is
a valid standalone reference, but there is no such possibility for A1).
How to interpret the value.
Position of a column.
How to interpret the value.
Position of a row.
Does RowCol use A1 semantic?
Does RowCol use R1C1 semantic?
Reference style of the RowCol.
Is RowCol a part (start or end) of row span?
Is RowCol a part (start or end) of column span?
Create a new with both row and columns specified.
The type used to interpret the row position.
The value for the row position.
The type used to interpret the column position.
The value for the column position.
Semantic of the reference.
Create a new with both row and columns specified.
Is the row reference absolute? If false, then relative.
The value for the row position.
Is the column reference absolute? If false, then relative.
The value for the column position.
Semantic of the reference.
Create a new with both row and columns specified
with relative values. Used mostly for A1 style.
The relative position of the row.
The relative position of the column.
Semantic of the reference.
Compares two objects by value. The result specifies whether
all properties of the two objects are equal.
Compares two objects by value. The result specifies whether
any property of the two objects is not equal.
Get a reference in A1 notation.
When RowCol doesn't use A1 semantic.
Get a reference in R1C1 notation.
When RowCol doesn't use R1C1 semantic.
Convert RowCol to R1C1.
If RowCol already is in R1C1, return it directly.
A row coordinate that should be used as an anchor for relative R1C1 reference.
A column coordinate that should be used as an anchor for relative R1C1 reference.
RowCol with R1C1 semantic.
Row or col is out of valid row or column number.
Convert RowCol to A1.
If RowCol already is in A1, return it directly. If converted RowCol
is out of sheet bounds, loop it.
A row coordinate that should be used as an anchor for relative R1C1 reference.
A column coordinate that should be used as an anchor for relative R1C1 reference.
RowCol with R1C1 semantic.
Row or col is out of valid row or column number.
String buffer where to write the output.
When RowCol is not in A1 notation.
String buffer where to write the output.
When RowCol is not in A1 notation.
Check whether the is of type
and all values are same as this one.
Check whether the all values of are same as
this one.
Returns a hash code for this .
Extension methods for building formulas.
Structure reference is basically a set of cells in an area of an intersection between a range of columns
in a table and a vertical range. This enum represents possible values. Thanks to the pattern of a structure
reference token, the vertical range of a formula is always continuous (i.e. no Headers and Totals
together).
The documentation calls it *Item specifier* and grammar *keywords*. Both rather unintuitive names, so *area*
is used instead.
Nothing was specified in the structure reference. Should have same impact as .
[#Data] - only data cells of a table, without headers or totals.
[#Headers] - only header rows of a table, if it exists. If there isn't header row, #REF!.
[#Totals] - only totals rows of a table, if it exists. If there isn't totals row, #REF!.
[#All] - all cells of a table.
[#This Row] - only the same data row as the referencing cell. #VALUE! if not on a data row
(e.g. headers or totals) or out of a table.
A range of a symbol in formula text.
Create a substring of a symbol.
Start index of symbol in formula text.
End index of symbol in formula text. Can be outside of text bounds, if symbol ends at the
last char of formula.
Length of a symbol.
Get range indexes.
A token for a formula input.
An error symbol id.
An symbol id for end of file. Mostly for compatibility with ANTLR.
A token ID or TokenType. Non-negative integer. The values are from Antlr grammar, starting with 1.
See FormulaLexer.tokens. The value -1 indicates an error and unrecognized token and is always
last token.
The starting index of a token, in code units (=chars).
Length of a token in code units (=chars). For non-error tokens, must be at least 1. Ignore for error token.
Parse token.
Parse token
Parse A1_REFERENCE token in R1C1 mode.
The span of a token.
Read the axis value. Can work for row or column.
The span of a token.
Index where is C/R.
Extract info about cell reference from a A1_REFERENCE token.
Read a structured name until the end bracket or column
Input span.
First index of expected name. It will either contain a bracket or first letter of column name.
Parsed name.
A symbol that represents a transformed symbol value. Should be used during AST transformation.
The text that replaced symbol or null, if there was no change.
Range of the symbol in original formula.
Length of the transformed symbol.
Create a symbol that is different from what was in the original formula.
Text of whole formula.
Range of the symbol in the formula.
The string of a transformed symbol.
Create a new symbol represented by a substring of an original formula. Generally used when
there is no modification of the symbol (i.e. just pass it as it is).
Text of whole formula.
Range of the symbol in the formula.
Get content of the symbol as a span. Doesn't allocate memory.
Get symbol as a text with extra text at the end.
Text to append at the end of the symbol text.
Get symbol text representation.
Unary operations of a formula.
Range operations are always after number operations.
Prefix plus operation.
Prefix minus operation.
Suffix percent operation.
Prefix range intersection operation.
Suffix range spill operation.