spreadsheet_intelligence.utils package#
Submodules#
spreadsheet_intelligence.utils.helpers module#
- spreadsheet_intelligence.utils.helpers.ensure_not_none(value: T | None, arg_name: str = 'value') T [source]#
- spreadsheet_intelligence.utils.helpers.get_required_attribute(element: Element, attr_name: str) str [source]#
Retrieve a required attribute from an XML element.
- Parameters:
element (ET.Element) – The XML element to retrieve the attribute from.
attr_name (str) – The name of the attribute to retrieve.
- Returns:
The value of the attribute.
- Return type:
str
- Raises:
ValueError – If the attribute is missing.
- spreadsheet_intelligence.utils.helpers.get_required_element(element: Element, path: str, namespaces: Dict[str, str] | None = None) Element [source]#
Retrieve a required child element from an XML element.
- Parameters:
element (ET.Element) – The XML element to retrieve the child from.
path (str) – The XPath to the child element.
namespaces (Optional[Dict[str, str]]) – XML namespaces to use during the search.
- Returns:
The found child element.
- Return type:
ET.Element
- Raises:
ValueError – If the child element is missing.
- spreadsheet_intelligence.utils.helpers.get_element_text(element: Element, path: str, namespaces: Dict[str, str] | None = None) str [source]#
- spreadsheet_intelligence.utils.helpers.get_attribute_or_none(element: Element, attr_name: str, default: str | None = None) str | None [source]#
- spreadsheet_intelligence.utils.helpers.get_attribute_or_default(element: Element, attr_name: str, default: str) str [source]#
- spreadsheet_intelligence.utils.helpers.get_element_or_none(element: Element, path: str, namespaces: Dict[str, str] | None = None) Element | None [source]#
- spreadsheet_intelligence.utils.helpers.emu_to_cm(emu: float) float [source]#
Convert EMU (English Metric Units) to centimeters.
- Parameters:
emu (float) – The value in EMU to be converted.
- Returns:
The converted value in centimeters, rounded to two decimal places.
- Return type:
float
- spreadsheet_intelligence.utils.helpers.apply_rotation(p: Tuple[float, float], c: Tuple[float, float], rotation: float) Tuple[float, float] [source]#
Apply rotation to a point around a center.
- Parameters:
p (Tuple[float, float]) – The point to be rotated.
c (Tuple[float, float]) – The center of rotation.
rotation (float) – The rotation angle in degrees.
- Returns:
The new coordinates of the point after rotation.
- Return type:
Tuple[float, float]
- spreadsheet_intelligence.utils.helpers.apply_scale(x: float, y: float, w: float, h: float, scale: float) Tuple[float, float, float, float] [source]#
Apply scaling to a rectangle defined by its top-left corner and dimensions.
- Parameters:
x (float) – The x-coordinate of the top-left corner.
y (float) – The y-coordinate of the top-left corner.
w (float) – The width of the rectangle.
h (float) – The height of the rectangle.
scale (float) – The scaling factor.
- Returns:
The new coordinates and dimensions after scaling.
- Return type:
Tuple[float, float, float, float]
- spreadsheet_intelligence.utils.helpers.apply_flip(p: Tuple[float, float], c: Tuple[float, float], flip_h: bool, flip_v: bool) Tuple[float, float] [source]#
Apply horizontal and/or vertical flip to a point around a center.
- Parameters:
p (Tuple[float, float]) – The point to be flipped.
c (Tuple[float, float]) – The center of flipping.
flip_h (bool) – Whether to apply horizontal flip.
flip_v (bool) – Whether to apply vertical flip.
- Returns:
The new coordinates of the point after flipping.
- Return type:
Tuple[float, float]