XlsxWriter.Validation
(xlsx_writer v0.7.5)
Copy Markdown
Validation functions for XlsxWriter inputs.
This module provides validation helpers to ensure data integrity and provide helpful error messages before data reaches the Rust NIF.
Summary
Functions
Validates that row and column indices are non-negative.
Validates format options list, ensuring color values are strings.
Validates that image binary data is not empty.
Validates rich string segments.
Validates that a value is a supported data type.
Functions
Validates that row and column indices are non-negative.
Parameters
row- The row index (0-based)col- The column index (0-based)
Raises
ArgumentErrorif row or column is negative
Examples
iex> XlsxWriter.Validation.validate_cell_position!(0, 0)
:ok
iex> XlsxWriter.Validation.validate_cell_position!(-1, 0)
** (ArgumentError) Row index must be non-negative, got: -1
Validates format options list, ensuring color values are strings.
Checks all color-related format options to ensure they receive string hex color values (e.g., "#FF0000") and not other types like booleans or integers.
Parameters
formats- List of format tuples
Raises
ArgumentErrorif any color option has a non-string value
Examples
iex> XlsxWriter.Validation.validate_formats!([:bold, {:bg_color, "#FF0000"}])
:ok
iex> XlsxWriter.Validation.validate_formats!([{:font_color, true}])
** (XlsxWriter.Error) Format option :font_color expects a string hex color (e.g., "#FF0000"), got: true
Validates that image binary data is not empty.
Parameters
image_binary- Binary data for the image
Raises
ArgumentErrorif binary is empty
Examples
iex> XlsxWriter.Validation.validate_image_binary!(<<1, 2, 3>>)
:ok
iex> XlsxWriter.Validation.validate_image_binary!(<<>>)
** (ArgumentError) Image binary cannot be empty
Validates rich string segments.
Each segment must be a tuple of {text, formats} where:
textis a binary stringformatsis a list of format options
Parameters
segments- List of segment tuples
Raises
ArgumentErrorif segments is not a listArgumentErrorif any segment is not a valid{text, formats}tuple
Examples
iex> XlsxWriter.Validation.validate_rich_string_segments!([{"Bold ", [:bold]}, {"Normal", []}])
:ok
iex> XlsxWriter.Validation.validate_rich_string_segments!([])
** (ArgumentError) Rich string segments cannot be empty
iex> XlsxWriter.Validation.validate_rich_string_segments!("not a list")
** (ArgumentError) Rich string segments must be a list, got: "not a list"
Validates that a value is a supported data type.
Parameters
value- The value to validate
Raises
ArgumentErrorif the data type is not supported
Examples
iex> XlsxWriter.Validation.validate_supported_type!("string")
:ok
iex> XlsxWriter.Validation.validate_supported_type!(123)
:ok
iex> XlsxWriter.Validation.validate_supported_type!(self())
** (XlsxWriter.Error) The data type for value "#PID<0.123.0>" is not supported.