UmyaSpreadsheet.CellFunctions (umya_spreadsheet_ex v0.7.0)

View Source

Functions for manipulating individual cells in a spreadsheet.

Summary

Functions

Gets the number format code of a cell.

Gets the hidden status of a cell.

Gets the locked status of a cell.

Gets the pattern type of a cell's fill.

Gets the wrap text setting of a cell.

Gets the formatted value of a cell (as displayed in Excel).

Removes a cell from the spreadsheet.

Sets the text indentation level for a cell.

Sets the text rotation angle for a cell.

Functions

get_border_color(spreadsheet, sheet_name, cell_address, border_position)

Gets the border color of a cell.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1", "B5")
  • border_position - "top", "bottom", "left", "right", or "diagonal"

Returns

  • {:ok, color} where color is the border color in hex format (e.g., "#FF0000")
  • {:error, reason} on failure

get_border_style(spreadsheet, sheet_name, cell_address, border_position)

Gets the border style of a cell.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1", "B5")
  • border_position - "top", "bottom", "left", "right", or "diagonal"

Returns

  • {:ok, style} where style is the border style (e.g., "solid", "dashed", "dotted")
  • {:error, reason} on failure

get_cell_background_color(spreadsheet, sheet_name, cell_address)

Gets the background color of a cell.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1", "B5")

Returns

  • {:ok, color} where color is the background color in hex format (e.g., "#FFFFFF")
  • {:error, reason} on failure

get_cell_foreground_color(spreadsheet, sheet_name, cell_address)

Gets the foreground color of a cell.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1", "B5")

Returns

  • {:ok, color} where color is the foreground color in hex format (e.g., "#000000")
  • {:error, reason} on failure

get_cell_format_code(spreadsheet, sheet_name, cell_address)

Gets the number format code of a cell.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1", "B5")

Returns

  • {:ok, format_code} where format_code is the number format code (e.g., "0.00", "m/d/yyyy")
  • {:error, reason} on failure

get_cell_hidden(spreadsheet, sheet_name, cell_address)

Gets the hidden status of a cell.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1", "B5")

Returns

  • {:ok, hidden} where hidden is a boolean indicating if the cell is hidden
  • {:error, reason} on failure

get_cell_horizontal_alignment(spreadsheet, sheet_name, cell_address)

Gets the horizontal alignment of a cell.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1", "B5")

Returns

  • {:ok, alignment} where alignment is "general", "left", "center", "right", etc.
  • {:error, reason} on failure

get_cell_locked(spreadsheet, sheet_name, cell_address)

Gets the locked status of a cell.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1", "B5")

Returns

  • {:ok, locked} where locked is a boolean indicating if the cell is locked
  • {:error, reason} on failure

get_cell_number_format_id(spreadsheet, sheet_name, cell_address)

Gets the number format ID of a cell.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1", "B5")

Returns

  • {:ok, format_id} where format_id is the number format ID
  • {:error, reason} on failure

get_cell_pattern_type(spreadsheet, sheet_name, cell_address)

Gets the pattern type of a cell's fill.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1", "B5")

Returns

  • {:ok, pattern_type} where pattern_type is the pattern type (e.g., "solid", "none")
  • {:error, reason} on failure

get_cell_text_rotation(spreadsheet, sheet_name, cell_address)

Gets the text rotation of a cell.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1", "B5")

Returns

  • {:ok, angle} where angle is the rotation angle in degrees
  • {:error, reason} on failure

get_cell_value(spreadsheet, sheet_name, cell_address)

Gets the value of a cell.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1", "B5")

Returns

  • The cell value as a string
  • {:error, reason} on failure

Examples

{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
"Hello" = UmyaSpreadsheet.CellFunctions.get_cell_value(spreadsheet, "Sheet1", "A1")

get_cell_vertical_alignment(spreadsheet, sheet_name, cell_address)

Gets the vertical alignment of a cell.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1", "B5")

Returns

  • {:ok, alignment} where alignment is "top", "center", "bottom", etc.
  • {:error, reason} on failure

get_cell_wrap_text(spreadsheet, sheet_name, cell_address)

Gets the wrap text setting of a cell.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1", "B5")

Returns

  • {:ok, wrap} where wrap is a boolean indicating if text wrapping is enabled
  • {:error, reason} on failure

get_formatted_value(spreadsheet, sheet_name, cell_address)

Gets the formatted value of a cell (as displayed in Excel).

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1", "B5")

Returns

  • The formatted cell value as a string
  • {:error, reason} on failure

Examples

{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
"12/31/2023" = UmyaSpreadsheet.CellFunctions.get_formatted_value(spreadsheet, "Sheet1", "A1")

remove_cell(spreadsheet, sheet_name, cell_address)

Removes a cell from the spreadsheet.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1", "B5")

Returns

  • :ok on success
  • {:error, reason} on failure

Examples

{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
:ok = UmyaSpreadsheet.CellFunctions.remove_cell(spreadsheet, "Sheet1", "A1")

set_cell_alignment(spreadsheet, sheet_name, cell_address, horizontal, vertical)

Sets the cell alignment.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1", "B5")
  • horizontal - Horizontal alignment ("left", "center", "right", "justify")
  • vertical - Vertical alignment ("top", "center", "bottom")

Returns

  • :ok on success
  • {:error, reason} on failure

Examples

{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
:ok = UmyaSpreadsheet.CellFunctions.set_cell_alignment(spreadsheet, "Sheet1", "A1", "center", "center")

set_cell_indent(spreadsheet, sheet_name, cell_address, level)

Sets the text indentation level for a cell.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1", "B5")
  • level - The indentation level

Returns

  • :ok on success
  • {:error, reason} on failure

Examples

{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
:ok = UmyaSpreadsheet.CellFunctions.set_cell_indent(spreadsheet, "Sheet1", "A1", 2)

set_cell_rotation(spreadsheet, sheet_name, cell_address, angle)

Sets the text rotation angle for a cell.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1", "B5")
  • angle - The rotation angle in degrees

Returns

  • :ok on success
  • {:error, reason} on failure

Examples

{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
:ok = UmyaSpreadsheet.CellFunctions.set_cell_rotation(spreadsheet, "Sheet1", "A1", 45)

set_cell_value(spreadsheet, sheet_name, cell_address, value)

Sets the value of a cell.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1", "B5")
  • value - The value to set

Returns

  • :ok on success
  • {:error, reason} on failure

Examples

{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
:ok = UmyaSpreadsheet.CellFunctions.set_cell_value(spreadsheet, "Sheet1", "A1", "Hello")

set_number_format(spreadsheet, sheet_name, cell_address, format_code)

Sets the number format for a cell.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1", "B5")
  • format_code - The format code (e.g., "0.00", "m/d/yyyy")

Returns

  • :ok on success
  • {:error, reason} on failure

Examples

{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
# Set number format to 2 decimal places
:ok = UmyaSpreadsheet.CellFunctions.set_number_format(spreadsheet, "Sheet1", "A1", "0.00")
# Set date format
:ok = UmyaSpreadsheet.CellFunctions.set_number_format(spreadsheet, "Sheet1", "B1", "m/d/yyyy")

set_wrap_text(spreadsheet, sheet_name, cell_address, wrap)

Sets text wrapping for a cell.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1", "B5")
  • wrap - Boolean indicating whether to wrap text

Returns

  • :ok on success
  • {:error, reason} on failure

Examples

{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
:ok = UmyaSpreadsheet.CellFunctions.set_wrap_text(spreadsheet, "Sheet1", "A1", true)