docx_parser_converter.docx_parsers.utils module
- docx_parser_converter.docx_parsers.utils.convert_half_points_to_points(half_points: int) float[source]
Converts half-points to points.
- Parameters:
half_points (int) – The value in half-points.
- Returns:
The value in points.
- Return type:
float
Example
The following converts 24 half-points to points:
points = convert_half_points_to_points(24) print(points) # Output: 12.0
- docx_parser_converter.docx_parsers.utils.convert_twips_to_points(twips: int) float[source]
Converts twips (twentieths of a point) to points.
- Parameters:
twips (int) – The value in twips.
- Returns:
The value in points.
- Return type:
float
Example
The following converts 240 twips to points:
points = convert_twips_to_points(240) print(points) # Output: 12.0
- docx_parser_converter.docx_parsers.utils.extract_xml_root_from_docx(docx_file: bytes, xml_filename: str) Element[source]
Extracts the root element from the specified XML file within a DOCX file.
- Parameters:
docx_file (bytes) – The binary content of the DOCX file.
xml_filename (str) – The name of the XML file to extract (e.g., ‘document.xml’).
- Returns:
The root element of the extracted XML file.
- Return type:
ET.Element
Example
The following is an example of the structure of the XML file extracted:
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"> <!-- XML content here --> </w:document>
- docx_parser_converter.docx_parsers.utils.extract_xml_root_from_string(xml_content: str) Element[source]
Extracts the root element from an XML string.
- Parameters:
xml_content (str) – The XML content as a string.
- Returns:
The root element of the parsed XML.
- Return type:
ET.Element
- docx_parser_converter.docx_parsers.utils.merge_properties(base_props: BaseModel | None, derived_props: BaseModel | None) BaseModel | None[source]
Merges two sets of properties, with derived properties taking precedence over base properties.
- Parameters:
base_props (Union[BaseModel, None]) – The base properties.
derived_props (Union[BaseModel, None]) – The derived properties.
- Returns:
The merged properties.
- Return type:
Union[BaseModel, None]
Example
The following merges two Pydantic models:
base = ParagraphProperties(spacing=SpacingProperties(before_pt=10)) derived = ParagraphProperties(spacing=SpacingProperties(after_pt=20)) merged = merge_properties(base, derived) print(merged)