UmyaSpreadsheet.SheetFunctions (umya_spreadsheet_ex v0.7.0)
View SourceFunctions for manipulating sheets in a spreadsheet.
Summary
Functions
Merges cells in a specified range.
Adds a new sheet to the spreadsheet.
Clones an existing sheet.
Gets the currently active sheet tab index.
Gets the list of merged cell ranges in a sheet.
Gets the total number of sheets in the spreadsheet.
Gets a list of all sheet names in the spreadsheet.
Checks if a sheet is protected and gets protection details.
Gets the visibility state of a sheet.
Inserts new columns into a sheet.
Inserts new columns into a sheet using column index.
Inserts new rows into a sheet.
Moves a range of cells to a new position.
Removes columns from a sheet.
Removes columns from a sheet using column index.
Removes rows from a sheet.
Removes a sheet from the spreadsheet.
Renames an existing sheet.
Sets the protection for a sheet.
Sets the visibility state of a sheet.
Functions
Merges cells in a specified range.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheetrange
- The range to merge (e.g., "A1:B5")
Returns
:ok
on success{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
:ok = UmyaSpreadsheet.SheetFunctions.add_merge_cells(spreadsheet, "Sheet1", "A1:B2")
Adds a new sheet to the spreadsheet.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name for the new sheet
Returns
:ok
on success{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
:ok = UmyaSpreadsheet.SheetFunctions.add_sheet(spreadsheet, "NewSheet")
Clones an existing sheet.
Parameters
spreadsheet
- The spreadsheet structsource_sheet_name
- The name of the sheet to clonenew_sheet_name
- The name for the new sheet
Returns
:ok
on success{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
:ok = UmyaSpreadsheet.SheetFunctions.clone_sheet(spreadsheet, "Sheet1", "Sheet1 Copy")
Gets the currently active sheet tab index.
Parameters
spreadsheet
- The spreadsheet struct
Returns
{:ok, index}
on success where index is the 0-based active tab index{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
{:ok, 0} = UmyaSpreadsheet.SheetFunctions.get_active_sheet(spreadsheet)
Gets the list of merged cell ranges in a sheet.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheet
Returns
{:ok, ranges}
on success where ranges is a list of range strings{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
{:ok, ["A1:B2", "C3:D4"]} = UmyaSpreadsheet.SheetFunctions.get_merge_cells(spreadsheet, "Sheet1")
Gets the total number of sheets in the spreadsheet.
Parameters
spreadsheet
- The spreadsheet struct
Returns
- The number of sheets as an integer
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
3 = UmyaSpreadsheet.SheetFunctions.get_sheet_count(spreadsheet)
Gets a list of all sheet names in the spreadsheet.
Parameters
spreadsheet
- The spreadsheet struct
Returns
- A list of sheet names
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
["Sheet1", "Sheet2"] = UmyaSpreadsheet.SheetFunctions.get_sheet_names(spreadsheet)
Checks if a sheet is protected and gets protection details.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheet
Returns
{:ok, %{protected: boolean, details: map}}
on success{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
{:ok, %{protected: true, details: %{}}} = UmyaSpreadsheet.SheetFunctions.get_sheet_protection(spreadsheet, "Sheet1")
Gets the visibility state of a sheet.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheet
Returns
{:ok, state}
on success where state is "visible", "hidden", or "veryhidden"{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
{:ok, "visible"} = UmyaSpreadsheet.SheetFunctions.get_sheet_state(spreadsheet, "Sheet1")
Inserts new columns into a sheet.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheetcolumn
- The column letter where columns should be inserted (e.g., "C")amount
- The number of columns to insert
Returns
:ok
on success{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
# Insert 2 new columns at column C
:ok = UmyaSpreadsheet.SheetFunctions.insert_new_column(spreadsheet, "Sheet1", "C", 2)
Inserts new columns into a sheet using column index.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheetcolumn_index
- The column index (1-based) where columns should be insertedamount
- The number of columns to insert
Returns
:ok
on success{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
# Insert 2 new columns at column index 3 (column C)
:ok = UmyaSpreadsheet.SheetFunctions.insert_new_column_by_index(spreadsheet, "Sheet1", 3, 2)
Inserts new rows into a sheet.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheetrow_index
- The index where rows should be insertedamount
- The number of rows to insert
Returns
:ok
on success{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
# Insert 2 new rows at row 3
:ok = UmyaSpreadsheet.SheetFunctions.insert_new_row(spreadsheet, "Sheet1", 3, 2)
Moves a range of cells to a new position.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheetrange
- The range to move (e.g., "A1:B5")rows
- Number of rows to move (positive for down, negative for up)columns
- Number of columns to move (positive for right, negative for left)
Returns
:ok
on success{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
# Move range down 2 rows and right 3 columns
:ok = UmyaSpreadsheet.SheetFunctions.move_range(spreadsheet, "Sheet1", "A1:B5", 2, 3)
Removes columns from a sheet.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheetcolumn
- The column letter where columns should be removed from (e.g., "C")amount
- The number of columns to remove
Returns
:ok
on success{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
# Remove 2 columns starting from column C
:ok = UmyaSpreadsheet.SheetFunctions.remove_column(spreadsheet, "Sheet1", "C", 2)
Removes columns from a sheet using column index.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheetcolumn_index
- The column index (1-based) where columns should be removed fromamount
- The number of columns to remove
Returns
:ok
on success{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
# Remove 2 columns starting from column index 3 (column C)
:ok = UmyaSpreadsheet.SheetFunctions.remove_column_by_index(spreadsheet, "Sheet1", 3, 2)
Removes rows from a sheet.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheetrow_index
- The index where rows should be removed fromamount
- The number of rows to remove
Returns
:ok
on success{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
# Remove 2 rows starting from row 3
:ok = UmyaSpreadsheet.SheetFunctions.remove_row(spreadsheet, "Sheet1", 3, 2)
Removes a sheet from the spreadsheet.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheet to remove
Returns
:ok
on success{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
:ok = UmyaSpreadsheet.SheetFunctions.remove_sheet(spreadsheet, "Sheet3")
Renames an existing sheet.
Parameters
spreadsheet
- The spreadsheet structold_sheet_name
- The current name of the sheetnew_sheet_name
- The new name for the sheet
Returns
:ok
on success{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
:ok = UmyaSpreadsheet.SheetFunctions.rename_sheet(spreadsheet, "Sheet1", "Updated Sheet")
Sets the protection for a sheet.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheetpassword
- Optional password for the protectionis_protected
- Boolean indicating whether the sheet should be protected
Returns
:ok
on success{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
# Protect with password
:ok = UmyaSpreadsheet.SheetFunctions.set_sheet_protection(spreadsheet, "Sheet1", "password", true)
# Remove protection
:ok = UmyaSpreadsheet.SheetFunctions.set_sheet_protection(spreadsheet, "Sheet1", nil, false)
Sets the visibility state of a sheet.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheetstate
- The visibility state ("visible", "hidden", "veryhidden")
Returns
:ok
on success{:error, reason}
on failure
Examples
{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
:ok = UmyaSpreadsheet.SheetFunctions.set_sheet_state(spreadsheet, "Sheet1", "hidden")