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

validate_cell_position!(row, col)

Validates that row and column indices are non-negative.

Parameters

  • row - The row index (0-based)
  • col - The column index (0-based)

Raises

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

validate_formats!(formats)

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

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

validate_image_binary!(image_binary)

Validates that image binary data is not empty.

Parameters

  • image_binary - Binary data for the image

Raises

Examples

iex> XlsxWriter.Validation.validate_image_binary!(<<1, 2, 3>>)
:ok

iex> XlsxWriter.Validation.validate_image_binary!(<<>>)
** (ArgumentError) Image binary cannot be empty

validate_rich_string_segments!(segments)

Validates rich string segments.

Each segment must be a tuple of {text, formats} where:

  • text is a binary string
  • formats is a list of format options

Parameters

  • segments - List of segment tuples

Raises

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"

validate_supported_type!(value)

Validates that a value is a supported data type.

Parameters

  • value - The value to validate

Raises

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.