import_named_expression

Defined in header: <orcus/spreadsheet/import_interface.hpp>

class import_named_expression

Interface for importing named expressions or ranges.

This interface has two different methods for defining named expressions:

Generally speaking, set_named_expression() can be used to define both named expression and named range. However, the implementor may choose to apply a different syntax rule to parse an expression passed to set_named_range(), depending on the formula grammar defined via import_global_settings::set_default_formula_grammar(). For instance, the OpenDocument Spreadsheet format is known to use different syntax rules between named expressions and named ranges.

A named range is a special case of a named expression where the expression consists of only one single cell range token.

Here is a code example of how a named expression is defined:

import_named_expression* iface = ...;

// set the A1 on the first sheet as its origin (optional).
src_address_t origin{0, 0, 0};
iface->set_base_position(origin);
iface->set_named_expression("MyExpression", "SUM(A1:B10)+SUM(D1:D4)");
iface->commit();

Replace the above set_named_expression() call with set_named_range() if you wish to define a named range instead.

Public Functions

virtual ~import_named_expression()
virtual void set_base_position(const src_address_t &pos) = 0

Specify an optional base position, or origin, from which to evaluate a named expression. If not specified, the implementor should use the top-left corner cell on the first sheet as its origin.

Parameters:

pos – cell position to be used as the origin.

virtual void set_named_expression(std::string_view name, std::string_view expression) = 0

Set a named expression to the buffer.

Parameters:
  • name – name of the expression to be defined.

  • expression – expression to be associated with the name.

virtual void set_named_range(std::string_view name, std::string_view range) = 0

Set a named range to the buffer.

Parameters:
  • name – name of the expression to be defined.

  • range – range to be associated with the name.

virtual void commit() = 0

Commit the named expression or range currently in the buffer to the document.