UmyaSpreadsheet.ImageFunctions (umya_spreadsheet_ex v0.7.0)
View SourceFunctions for working with images in a spreadsheet.
Summary
Functions
Adds an image to a spreadsheet.
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
Adds an image to a spreadsheet.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheetcell_address
- The cell address (e.g., "A1") where the top-left corner of the image should be placedimage_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")
Changes an existing image in a spreadsheet to a new image.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheetcell_address
- The cell address (e.g., "A1") where the image is locatednew_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")
Extracts an image from a spreadsheet and saves it to a file.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheetcell_address
- The cell address (e.g., "A1") where the image is locatedoutput_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")
Gets the dimensions (width, height) of an image in a cell.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheetcell_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")
Gets comprehensive information about an image in a spreadsheet.
Parameters
spreadsheet
- The spreadsheet structsheet_name
- The name of the sheetcell_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")
Lists all images in a sheet with their positions and names.
Parameters
spreadsheet
- The spreadsheet structsheet_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)