sheet_view

Defined in header: <ixion/sheet_view.hpp>

class sheet_view

A named view of a sheet. A view takes a snapshot of the content of its base sheet when created; later edits to the base sheet do not show up in the view. The rows of the view can get sorted independently of the base sheet, and the view keeps track of which base row each of its rows shows.

Views get created and owned by model_context via its create_sheet_view() method, and stay valid until removed or until the model context gets destroyed.

Public Functions

sheet_view(const sheet_view&) = delete
sheet_view &operator=(const sheet_view&) = delete
~sheet_view()
sheet_t get_sheet() const
Returns:

Index of the base sheet this view was created from.

std::string_view get_name() const
Returns:

Name of this view, unique among the views of its base sheet.

cell_t get_celltype(const abs_rc_address_t &pos) const
Returns:

Type of the cell at the specified position of the view.

double get_numeric_value(const abs_rc_address_t &pos) const

Get a numeric representation of the cell value at the specified position of the view. A formula cell yields its cached result.

Parameters:

pos – Position of the cell.

Returns:

Numeric representation of the cell value.

bool get_boolean_value(const abs_rc_address_t &pos) const

Get a boolean representation of the cell value at the specified position of the view. A formula cell yields its cached result.

Parameters:

pos – Position of the cell.

Returns:

Boolean representation of the cell value.

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

Get the string value of the cell at the specified position of the view. It returns a valid string only when the cell is a string cell, or a formula cell with a cached string result.

Parameters:

pos – Position of the cell.

Returns:

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

const formula_cell *get_formula_cell(const abs_rc_address_t &pos) const
Returns:

Formula cell at the specified position of the view, or nullptr if the cell is not a formula cell.

void sort(const abs_rc_range_t &range, const sort_keys_t &keys)

Sort the rows of a range of this view in place. The rows of the range move as units across all of its columns; the cells outside the range never move. The base sheet stays untouched.

The sort is stable, and orders cells of different types as numeric values first, then strings, then false, then true, then error values, with empty cells always last regardless of the direction. String comparison is byte-wise. Formula cells sort by their cached results; a formula cell without a cached result sorts like an empty cell.

A formula group survives the sort when its members stay contiguous and in their original order; any other affected group gets ungrouped, with each member keeping its cached result. Adjacent cells sharing a formula regroup after the sort.

A later sort, such as by another key column or in the other direction, re-orders the rows as the view currently shows them, and the row mapping reported by to_base_row() and to_view_row() reflects the combined effect of all the sorts.

Parameters:
  • range – Range to sort.

  • keys – Sort keys in order of precedence. Every key column must lie within the columns of the range, and every key must specify its direction.

Throws:

std::invalid_argument – When the range does not fit within the sheet, no keys are given, a key column lies outside the range, or a key does not specify its direction.

row_t to_base_row(row_t view_row) const

Get the base sheet row that a row of this view shows.

Parameters:

view_row – Row position in this view.

Throws:

std::out_of_range – When the row position lies outside the sheet.

Returns:

Row position in the base sheet.

row_t to_view_row(row_t base_row) const

Get the row of this view that shows a base sheet row.

Parameters:

base_row – Row position in the base sheet.

Throws:

std::out_of_range – When the row position lies outside the sheet.

Returns:

Row position in this view.

void sort_table(std::string_view table_name, std::string_view column, sort_order_t order)

Sort the data rows of a table by one of its columns. The header row and the totals rows of the table stay in place; only the rows of its data area move, as units across all the columns of the table. The base sheet stays untouched. It does nothing when the table has no data rows.

Parameters:
  • table_name – Name of the table. The table must lie on the base sheet of this view.

  • column – Name of the table column to sort by.

  • order – Direction of the sort. It must not be unspecified.

Throws:

std::invalid_argument – When no table of that name exists, the table lies on another sheet, the table has no column of that name, or the direction is unspecified.

abs_rc_range_t get_data_range() const

Get the range that spans all the non-empty cells of this view.

Returns:

Range spanning the non-empty cells, or an invalid range when the view has no content.

void dump(std::ostream &os, sheet_dump_mode_t mode, const formula_name_resolver *resolver = nullptr) const

Dump the content of this view to an output stream as a human-readable text grid, in the format of model_context::dump_sheet() with an extra column showing the base sheet row of each row. Formula expressions get printed as they read on the base sheet.

Parameters:
  • os – Output stream to dump the view content to.

  • mode – Amount of detail to include in the output.

  • resolver – Name resolver that determines the column label style as well as the way formula expressions get printed in verbose mode. When null, an Excel A1 resolver gets created and used internally.

void refresh()

Replace the snapshot of this view with the current content of the base sheet, and re-apply the sorts of this view in their original order. The rows of the view do not jump: each row keeps showing the base row it showed before, with its refreshed content, even when the refreshed content no longer matches the sort order. Re-sorting happens only through explicit sort() and sort_table() calls.

Friends

friend class detail::model_context_impl