UmyaSpreadsheet.ImageFunctions (umya_spreadsheet_ex v0.7.0)

View Source

Functions for working with images in a spreadsheet.

Summary

Functions

Changes an existing image in a spreadsheet to a new image.

Extracts an image from a spreadsheet and saves it to a file.

Gets the dimensions (width, height) of an image in a cell.

Gets comprehensive information about an image in a spreadsheet.

Lists all images in a sheet with their positions and names.

Functions

add_image(spreadsheet, sheet_name, cell_address, image_path)

Adds an image to a spreadsheet.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1") where the top-left corner of the image should be placed
  • image_path - The path to the image file

Returns

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

Examples

{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
:ok = UmyaSpreadsheet.ImageFunctions.add_image(spreadsheet, "Sheet1", "C5", "path/to/image.png")

change_image(spreadsheet, sheet_name, cell_address, new_image_path)

Changes an existing image in a spreadsheet to a new image.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1") where the image is located
  • new_image_path - The path to the new image file

Returns

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

Examples

{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
:ok = UmyaSpreadsheet.ImageFunctions.change_image(spreadsheet, "Sheet1", "C5", "path/to/new_image.png")

download_image(spreadsheet, sheet_name, cell_address, output_path)

Extracts an image from a spreadsheet and saves it to a file.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet
  • cell_address - The cell address (e.g., "A1") where the image is located
  • output_path - The path where the image should be saved

Returns

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

Examples

{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
:ok = UmyaSpreadsheet.ImageFunctions.download_image(spreadsheet, "Sheet1", "C5", "extracted_image.png")

get_image_dimensions(spreadsheet, sheet_name, cell_address)

Gets the dimensions (width, height) of an image in a cell.

Parameters

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

Returns

  • {:ok, {width, height}} where width and height are in pixels
  • {:error, reason} on failure

Examples

{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
{:ok, {width, height}} = UmyaSpreadsheet.ImageFunctions.get_image_dimensions(spreadsheet, "Sheet1", "C5")

get_image_info(spreadsheet, sheet_name, cell_address)

Gets comprehensive information about an image in a spreadsheet.

Parameters

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

Returns

  • {:ok, {name, position, width, height}} with the image details
  • {:error, reason} on failure

Examples

{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
{:ok, {name, pos, width, height}} = UmyaSpreadsheet.ImageFunctions.get_image_info(spreadsheet, "Sheet1", "C5")

# Print the image information
IO.puts("Image '" <> name <>"' at position " <> pos <>", dimensions: "<>width{}"x"<>height<>" pixels")

list_images(spreadsheet, sheet_name)

Lists all images in a sheet with their positions and names.

Parameters

  • spreadsheet - The spreadsheet struct
  • sheet_name - The name of the sheet

Returns

  • {:ok, [{coordinate, image_name}, ...]} with a list of image coordinates and names
  • {:error, reason} on failure

Examples

{:ok, spreadsheet} = UmyaSpreadsheet.read_file("input.xlsx")
{:ok, images} = UmyaSpreadsheet.ImageFunctions.list_images(spreadsheet, "Sheet1")

# Print all images in the sheet
Enum.each(images, fn {coord, img_name} ->
  IO.puts("Image '#{img_name}' at position #{coord}")
end)