document

Defined in header: <ixion/document.hpp>

class document

Higher level document representation designed to handle both cell value storage as well as formula cell calculations.

Public Functions

document()

Constructor. Cell addresses given as strings, as well as formula expressions, use the Excel A1 syntax.

document(formula_name_resolver_t cell_address_type)

Constructor with custom cell address type.

Parameters:

cell_address_type – cell address type to use for cell addresses represented by string values, as well as for formula expressions.

~document()
void append_sheet(std::string name)

Append a new sheet to the document.

Parameters:

name – Name of the sheet. It must be unique within the document.

sheet_t append_sheet_copy(sheet_t src, std::string name)

Append a new sheet to the document as a copy of an existing sheet. All cells of the source sheet get copied over to the new sheet, and the calculation results of the copied formula cells carry over as well. Those formula cells whose carried-over results may no longer be valid on the new sheet get marked for re-calculation, which the next calculate() call picks up.

Parameters:
  • src – Index of the sheet to copy.

  • name – Name of the sheet to be inserted. It must be unique within the document, else a model_context_error exception gets thrown.

Throws:
  • model_context_error – When the sheet name already exists.

  • std::invalid_argument – When the source sheet index is invalid.

Returns:

Sheet index of the inserted sheet.

void set_sheet_name(sheet_t sheet, std::string name)

Set a new name to an existing sheet.

Parameters:
  • sheet – 0-based sheet index.

  • name – New name of a sheet.

const model_context &get_model_context() const

Get read-only access to the underlying model context, for instance to dump the content of a sheet or to iterate over its cells.

Returns:

Model context this document stores its cells in.

cell_access get_cell_access(const cell_pos &pos) const

Get an accessor for a cell, for repeated queries on the same cell.

Parameters:

pos – Position of the cell.

Returns:

Accessor for the cell.

void set_numeric_cell(const cell_pos &pos, double val)

Set a numeric value to a cell, replacing its current content. The formula cells depending on the cell get re-calculated by the next calculate() call.

Parameters:
  • pos – Position of the cell.

  • val – Numeric value.

void set_string_cell(const cell_pos &pos, std::string_view s)

Set a string value to a cell, replacing its current content. The formula cells depending on the cell get re-calculated by the next calculate() call.

Parameters:
  • pos – Position of the cell.

  • s – String value.

void set_boolean_cell(const cell_pos &pos, bool val)

Set a boolean value to a cell, replacing its current content. The formula cells depending on the cell get re-calculated by the next calculate() call.

Parameters:
  • pos – Position of the cell.

  • val – Boolean value.

void empty_cell(const cell_pos &pos)

Empty a cell, discarding whatever value it holds. The formula cells depending on the cell get re-calculated by the next calculate() call.

Parameters:

pos – Position of the cell.

double get_numeric_value(const cell_pos &pos) const

Get a numeric representation of the cell value. For a formula cell, this is the numeric value of its result.

Parameters:

pos – Position of the cell.

Returns:

Numeric representation of the cell value.

std::string_view get_string_value(const cell_pos &pos) const

Get the string value of a cell. Only a string cell, or a formula cell with a string result, has one.

Parameters:

pos – Position of the cell.

Returns:

String value of the cell, or an empty view if the cell holds no string.

void set_formula_cell(const cell_pos &pos, std::string_view formula)

Set a formula to a cell, replacing its current content. The formula gets parsed in the cell address syntax the document was constructed with, and the cell gets calculated by the next calculate() call.

Parameters:
  • pos – Position of the cell.

  • formula – Formula expression, without a leading ‘=’.

void calculate(size_t thread_count)

Calculate all the “dirty” formula cells in the document.

Parameters:

thread_count – number of threads to use to perform calculation. When 0 is specified, it only uses the main thread.

struct cell_pos

Position of a cell, given either as a string in the cell address syntax the document was constructed with, such as “Sheet1!A1”, or as an absolute address. A string without a sheet name refers to the first sheet.

Public Types

enum class cp_type

How the position is given.

Values:

enumerator string
enumerator address

Public Functions

cell_pos() = delete
cell_pos(const char *p)

Position as a null-terminated string.

cell_pos(std::string_view s)

Position as a string.

cell_pos(const std::string &s)

Position as a string.

cell_pos(const abs_address_t &addr)

Position as an absolute address.

cell_pos(const cell_pos &other)

Copy constructor.

cell_pos &operator=(const cell_pos &other)

Copy assignment.

Public Members

cp_type type

How the position is given.

std::variant<std::string_view, ixion::abs_address_t> value

The position, as a string or as an address depending on type.