Class: IronCalc::UserModel

Inherits:
Object
  • Object
show all
Defined in:
lib/ironcalc/native_methods.rb,
lib/ironcalc/model.rb

Overview

The recommended, higher-level IronCalc API. Auto-evaluates after every action and records diffs for collaboration (#flush_send_queue / #apply_external_diffs). Mirrors IronCalc’s WebAssembly binding and is a superset of the Python binding’s ‘UserModel`. Styling is per-property via #update_range_style (the Hash convenience #set_cell_style is layered on top).

Instance Method Summary collapse

Instance Method Details

#apply_external_diffs(diffs) ⇒ void

This method returns an undefined value.

Applies a peer’s diff blob (from #flush_send_queue) for collaboration.

Parameters:

  • diffs (String)

    binary diff blob

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 303

#can_redoBoolean

Returns:

  • (Boolean)


# File 'lib/ironcalc/native_methods.rb', line 331

#can_undoBoolean

Returns:

  • (Boolean)


# File 'lib/ironcalc/native_methods.rb', line 328

#clear_cell_contents(sheet, row, column) ⇒ void

This method returns an undefined value.

Clears a cell’s contents (not its style).

Parameters:

  • sheet (Integer)
  • row (Integer)
  • column (Integer)

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 343

#delete_columns(sheet, column, column_count) ⇒ void

This method returns an undefined value.

Parameters:

  • sheet (Integer)
  • column (Integer)
  • column_count (Integer)

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 413

#delete_rows(sheet, row, row_count) ⇒ void

This method returns an undefined value.

Parameters:

  • sheet (Integer)
  • row (Integer)
  • row_count (Integer)

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 406

#delete_sheet(sheet) ⇒ void

This method returns an undefined value.

Parameters:

  • sheet (Integer)

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 484

#evaluatevoid

This method returns an undefined value.

Forces a recalculation. Usually unnecessary — the user model auto-evaluates after each action; exposed for parity.



# File 'lib/ironcalc/native_methods.rb', line 313

#flush_send_queueString

Returns and clears the queued diffs to broadcast to collaborators.

Returns:

  • (String)

    binary diff blob



# File 'lib/ironcalc/native_methods.rb', line 309

#get_cell_content(sheet, row, column) ⇒ String

Returns the cell’s content: formula or literal text.

Parameters:

  • sheet (Integer)
  • row (Integer)
  • column (Integer)

Returns:

  • (String)

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 351

#get_cell_style(sheet, row, column) ⇒ Hash

Returns the cell style as a Hash with string keys, like Model#get_cell_style.

Parameters:

  • sheet (Integer)

    0-based sheet index

  • row (Integer)

    1-based row

  • column (Integer)

    1-based column

Returns:

  • (Hash)

Raises:

  • (IronCalc::Error)


43
44
45
# File 'lib/ironcalc/model.rb', line 43

def get_cell_style(sheet, row, column)
  JSON.parse(get_cell_style_json(sheet, row, column))
end

#get_cell_style_json(sheet, row, column) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

JSON backing for ‘get_cell_style`. Prefer the Hash-returning wrapper.

Returns:

  • (String)


# File 'lib/ironcalc/native_methods.rb', line 375

#get_cell_type(sheet, row, column) ⇒ Symbol

Returns the cell type as a Symbol (see IronCalc#get_cell_type).

Parameters:

  • sheet (Integer)
  • row (Integer)
  • column (Integer)

Returns:

  • (Symbol)

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 359

#get_column_width(sheet, column) ⇒ Float

Returns width in pixels.

Parameters:

  • sheet (Integer)
  • column (Integer)

Returns:

  • (Float)

    width in pixels

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 420

#get_formatted_cell_value(sheet, row, column) ⇒ String

Returns the cell’s value formatted as displayed.

Parameters:

  • sheet (Integer)
  • row (Integer)
  • column (Integer)

Returns:

  • (String)

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 367

#get_frozen_columns_count(sheet) ⇒ Integer

Parameters:

  • sheet (Integer)

Returns:

  • (Integer)

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 446

#get_frozen_rows_count(sheet) ⇒ Integer

Parameters:

  • sheet (Integer)

Returns:

  • (Integer)

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 451

#get_row_height(sheet, row) ⇒ Float

Returns height in pixels.

Parameters:

  • sheet (Integer)
  • row (Integer)

Returns:

  • (Float)

    height in pixels

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 426

#get_sheet_dimensions(sheet) ⇒ Array(Integer, Integer, Integer, Integer)

Returns [min_row, max_row, min_column, max_column] over non-empty cells.

Parameters:

  • sheet (Integer)

Returns:

  • (Array(Integer, Integer, Integer, Integer))

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 495

#get_worksheets_propertiesArray<Hash>

Returns one Hash per sheet with symbol keys :name, :state, :sheet_id and :color.

Returns:

  • (Array<Hash>)


# File 'lib/ironcalc/native_methods.rb', line 468

#insert_columns(sheet, column, column_count) ⇒ void

This method returns an undefined value.

Parameters:

  • sheet (Integer)
  • column (Integer)
  • column_count (Integer)

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 399

#insert_rows(sheet, row, row_count) ⇒ void

This method returns an undefined value.

Parameters:

  • sheet (Integer)
  • row (Integer)
  • row_count (Integer)

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 392

#new_sheetvoid

This method returns an undefined value.

Adds a new sheet with an auto-generated name.

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 479

#redovoid

This method returns an undefined value.

Redoes the last undone change.

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 323

#rename_sheet(sheet, new_name) ⇒ void

This method returns an undefined value.

Parameters:

  • sheet (Integer)
  • new_name (String)

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 489

#save_to_icalc(file) ⇒ void

This method returns an undefined value.

Saves the workbook to the internal binary icalc format.

Parameters:

  • file (String)

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 293

#save_to_xlsx(file) ⇒ void

This method returns an undefined value.

Saves the workbook to an xlsx file. Fails if the file already exists.

Parameters:

  • file (String)

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 287

#set_cell_style(sheet, row, column, style) ⇒ void

This method returns an undefined value.

Sets the cell style from a Hash (or JSON string). The user model has no whole-style setter; styling is per-property via the engine’s #update_range_style (mirroring the WASM binding). This convenience flattens the Hash and applies each leaf with #update_range_style.

Parameters:

  • sheet (Integer)

    0-based sheet index

  • row (Integer)

    1-based row

  • column (Integer)

    1-based column

  • style (Hash, String)

    the style as a Hash or JSON string

Raises:

  • (IronCalc::Error)


58
59
60
61
62
63
# File 'lib/ironcalc/model.rb', line 58

def set_cell_style(sheet, row, column, style)
  desired = style.is_a?(String) ? JSON.parse(style) : style
  flatten_style(desired).each do |path, value|
    update_range_style(sheet, row, column, path, value.to_s)
  end
end

#set_column_width(sheet, column, width) ⇒ void

This method returns an undefined value.

Parameters:

  • sheet (Integer)
  • column (Integer)
  • width (Float)

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 432

#set_frozen_columns_count(sheet, count) ⇒ void

This method returns an undefined value.

Parameters:

  • sheet (Integer)
  • count (Integer)

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 456

#set_frozen_rows_count(sheet, count) ⇒ void

This method returns an undefined value.

Parameters:

  • sheet (Integer)
  • count (Integer)

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 462

#set_row_height(sheet, row, height) ⇒ void

This method returns an undefined value.

Parameters:

  • sheet (Integer)
  • row (Integer)
  • height (Float)

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 439

#set_sheet_color(sheet, color) ⇒ void

This method returns an undefined value.

Parameters:

  • sheet (Integer)
  • color (String)

    hex color, e.g. “#FF0000”

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 473

#set_user_input(sheet, row, column, value) ⇒ void

This method returns an undefined value.

Sets a cell’s raw input (literal or formula). Triggers recalculation.

Parameters:

  • sheet (Integer)
  • row (Integer)
  • column (Integer)
  • value (String)

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 334

#to_bytesString

Serializes the workbook to icalc bytes.

Returns:

  • (String)

    binary string



# File 'lib/ironcalc/native_methods.rb', line 299

#undovoid

This method returns an undefined value.

Undoes the last change.

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 318

#update_range_style(sheet, row, column, style_path, value) ⇒ void

This method returns an undefined value.

Sets a single style property on a cell, e.g. update_range_style(0, 1, 1, “font.b”, “true”). This is the user model’s styling primitive (mirrors the WASM binding); ‘set_cell_style` wraps it for whole-Hash convenience.

Parameters:

  • sheet (Integer)
  • row (Integer)
  • column (Integer)
  • style_path (String)

    dotted path, e.g. “font.b”, “fill.fg_color”

  • value (String)

Raises:

  • (IronCalc::Error)


# File 'lib/ironcalc/native_methods.rb', line 380