Class: IronCalc::Model

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

Overview

The raw IronCalc API. You must call #evaluate yourself after changing inputs; misuse can leave the workbook in an inconsistent state. This mirrors the Python binding's Model. For most uses prefer UserModel, which auto-evaluates.

Instance Method Summary collapse

Instance Method Details

#add_sheet(name) ⇒ void

This method returns an undefined value.

Adds a new sheet with the given name.

Parameters:

  • name (String)

Raises:

  • (IronCalc::Error)


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

#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 117

#delete_columns(sheet, column, column_count) ⇒ void

This method returns an undefined value.

Deletes +column_count+ columns starting at +column+.

Parameters:

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

Raises:

  • (IronCalc::Error)


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

#delete_rows(sheet, row, row_count) ⇒ void

This method returns an undefined value.

Deletes +row_count+ rows starting at +row+.

Parameters:

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

Raises:

  • (IronCalc::Error)


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

#delete_sheet(sheet) ⇒ void

This method returns an undefined value.

Parameters:

  • sheet (Integer)

Raises:

  • (IronCalc::Error)


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

#evaluatevoid

This method returns an undefined value.

Recalculates the whole workbook. Call after #set_user_input.



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

#get_cell_content(sheet, row, column) ⇒ String

Returns the cell's content: the formula (e.g. "=A1+1") or literal text.

Parameters:

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

Returns:

  • (String)

Raises:

  • (IronCalc::Error)


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

#get_cell_style(sheet, row, column) ⇒ Hash

Returns the cell style as a Hash with string keys (snake_case, matching the engine's serde field names), e.g. { "num_fmt" => "general", "font" => { "b" => false, ... }, ... }

Parameters:

  • sheet (Integer)

    0-based sheet index

  • row (Integer)

    1-based row

  • column (Integer)

    1-based column

Returns:

  • (Hash)

Raises:

  • (IronCalc::Error)


17
18
19
# File 'lib/ironcalc/model.rb', line 17

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 150

#get_cell_type(sheet, row, column) ⇒ Symbol

Returns the cell type as a Symbol: +:number+, +:text+, +:logical_value+, +:error_value+, +:array+ or +:compound_data+.

Parameters:

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

Returns:

  • (Symbol)

Raises:

  • (IronCalc::Error)


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

#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 192

#get_formatted_cell_value(sheet, row, column) ⇒ String

Returns the cell's value formatted as displayed (number format applied).

Parameters:

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

Returns:

  • (String)

Raises:

  • (IronCalc::Error)


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

#get_frozen_columns_count(sheet) ⇒ Integer

Parameters:

  • sheet (Integer)

Returns:

  • (Integer)

Raises:

  • (IronCalc::Error)


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

#get_frozen_rows_count(sheet) ⇒ Integer

Parameters:

  • sheet (Integer)

Returns:

  • (Integer)

Raises:

  • (IronCalc::Error)


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

#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 198

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

Returns +[min_row, max_row, min_column, max_column]+ over non-empty cells (an empty sheet returns +[1, 1, 1, 1]+).

Parameters:

  • sheet (Integer)

Returns:

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

Raises:

  • (IronCalc::Error)


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

#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 240

#insert_columns(sheet, column, column_count) ⇒ void

This method returns an undefined value.

Inserts +column_count+ columns before +column+.

Parameters:

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

Raises:

  • (IronCalc::Error)


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

#insert_rows(sheet, row, row_count) ⇒ void

This method returns an undefined value.

Inserts +row_count+ rows before +row+.

Parameters:

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

Raises:

  • (IronCalc::Error)


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

#new_sheetvoid

This method returns an undefined value.

Adds a new sheet with an auto-generated name.



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

#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 266

#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 94

#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 88

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

This method returns an undefined value.

Sets the cell style from a Hash (snake_case keys) or a JSON string.

Parameters:

  • sheet (Integer)

    0-based sheet index

  • row (Integer)

    1-based row

  • column (Integer)

    1-based column

  • style (Hash, String)

    the full style as a Hash or JSON string

Raises:

  • (IronCalc::Error)


29
30
31
32
# File 'lib/ironcalc/model.rb', line 29

def set_cell_style(sheet, row, column, style)
  json = style.is_a?(String) ? style : JSON.generate(style)
  set_cell_style_json(sheet, row, column, json)
end

#set_cell_style_json(sheet, row, column, style_json) ⇒ void

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.

This method returns an undefined value.

JSON backing for set_cell_style. Prefer the Hash-accepting wrapper.



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

#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 204

#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 228

#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 234

#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 211

#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 245

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

This method returns an undefined value.

Sets a cell's raw input (a literal or a formula like "=A1+1").

Parameters:

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

Raises:

  • (IronCalc::Error)


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

#to_bytesString

Serializes the workbook to icalc bytes (load with IronCalc.load_from_bytes).

Returns:

  • (String)

    binary string



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