docx_plus.core.borders¶
The CT_Border shape, shared by every border edge in the format.
ECMA-376 uses one complex type for the four sides of <w:pgBorders>
(17.6.10), of <w:tblBorders> (17.4.39), and of <w:tcBorders>
(17.4.67), plus the inside and diagonal edges tables add — all with the
same four attributes. Border shipped from docx_plus.layout in v0.2
and moved here in v0.5 when table borders became a second consumer;
docx_plus.layout.Border still resolves to this class.
One default is worth knowing: space is 24 points, which is what
Word's UI emits for a page border. Word writes w:space="0" on table
and cell borders, so table writers override it rather than inheriting.
docx_plus.core.borders ¶
The CT_Border shape, shared by page, table, and cell borders.
ECMA-376 uses one complex type for every border edge in the format: the
four sides of <w:pgBorders> (17.6.10), of <w:tblBorders>
(17.4.39), and of <w:tcBorders> (17.4.67), plus the inside and
diagonal edges tables add. All of them carry the same four attributes —
style, thickness, color, and offset — so the dataclass and its
serializer live here rather than in whichever capability package needed
them first.
layout/borders.py shipped :class:Border in v0.2 and still
re-exports it, so docx_plus.layout.Border keeps working.
This module depends on nothing above core (SPEC §9.1).
Border
dataclass
¶
One border edge.
Attributes:
| Name | Type | Description |
|---|---|---|
style |
str
|
ECMA-376 17.18.2 border style name. Common values:
|
size |
int
|
Border thickness in eighths of a point (so |
color |
str
|
|
space |
int
|
Gap between the reference edge and the border, in points. ECMA-376 caps this at 31. The default |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
__post_init__ ¶
Validate the fields against their ECMA-376 simple types.
Source code in docx_plus/core/borders.py
border_attrs ¶
Serialize border to the CT_Border attribute mapping.
Every border edge in the format takes the same four attributes, so every writer — page, table, cell — goes through this.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
border
|
Border
|
The border to serialize. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
A |
dict[str, str]
|
mapping ready to splat into :func: |