Skip to content

Column

Column class for “table:table-column” tag.

Classes:

Name Description
Column

A Column of a table, “table:table-column”.

Column

Bases: Element

A Column of a table, “table:table-column”.

Methods:

Name Description
__init__

A Column of a table, “table:table-column”.

__repr__
get_default_cell_style

Get the default cell style for the column.

set_default_cell_style

Set the default cell style for the column.

Attributes:

Name Type Description
clone Column

Return a clone of the column.

default_cell_style str | None

Get or set the default cell style for the column.

repeated int | None

Get or set the number of times the column is repeated.

style str | None

Get or set the style of the column itself.

x int | None
Source code in odfdo/column.py
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
class Column(Element):
    """A Column of a table, "table:table-column"."""

    _tag = "table:table-column"

    def __init__(
        self,
        default_cell_style: str | None = None,
        repeated: int | None = None,
        style: str | None = None,
        **kwargs: Any,
    ) -> None:
        """A Column of a table, "table:table-column".

        This constructor creates a column element with an optional style.
        The default cell style can be set for the entire column. If the
        properties apply to multiple columns, the number of repeated columns
        can be specified.

        Columns do not contain cells themselves, but only styling information.

        Note:
            It is generally not necessary to create columns by hand; the
            higher-level Table API should be used instead.

        Args:
            default_cell_style: The name of the
                default style to apply to cells in this column.
            repeated: The number of times this column
                should be repeated. Must be greater than 1.
            style: The name of the style to apply to
                the column itself.
        """
        super().__init__(**kwargs)
        self.x: int | None = None
        if self._do_init:
            if default_cell_style:
                self.default_cell_style = default_cell_style
            if repeated and repeated > 1:
                self.repeated = repeated
            if style:
                self.style = style

    def __repr__(self) -> str:
        return f"<{self.__class__.__name__} x={self.x}>"

    @property
    def clone(self) -> Column:
        """Return a clone of the column."""
        clone: Column = Element.clone.fget(self)  # type: ignore[attr-defined]
        clone.x = self.x
        return clone

    def get_default_cell_style(self) -> str | None:
        """Get the default cell style for the column.

        (See also the `default_cell_style` property.)

        Returns:
            str or None: The name of the default cell style, or None if not set.
        """
        return self.get_attribute_string("table:default-cell-style-name")

    def set_default_cell_style(self, style: Style | str | None) -> None:
        """Set the default cell style for the column.

        (See also the `default_cell_style` property.)

        Args:
            style: The style to apply. Can be a Style
                object, the name of a style, or None to remove the style.
        """
        self.set_style_attribute("table:default-cell-style-name", style)

    @property
    def default_cell_style(self) -> str | None:
        """Get or set the default cell style for the column.

        Returns:
            str or None: The name of the default cell style, or None if not set.
        """
        return self.get_attribute_string("table:default-cell-style-name")

    @default_cell_style.setter
    def default_cell_style(self, style: Style | str | None) -> None:
        self.set_style_attribute("table:default-cell-style-name", style)

    def _set_repeated(self, repeated: int | None) -> None:
        """Set the number of times the column is repeated.

        This is an internal method that sets the 'table:number-columns-repeated'
        attribute without triggering cache updates. Use None to remove the
        attribute.

        Args:
            repeated: The number of times the column should be
                repeated. If None or less than 2, the attribute is removed.
        """
        if repeated is None or repeated < 2:
            with contextlib.suppress(KeyError):
                self.del_attribute("table:number-columns-repeated")
            return
        self.set_attribute("table:number-columns-repeated", str(repeated))

    @property
    def repeated(self) -> int | None:
        """Get or set the number of times the column is repeated.

        This property is typically None when using the higher-level table API.

        Returns:
            int or None: The number of repetitions, or None if not repeated.
        """
        repeated = self.get_attribute("table:number-columns-repeated")
        if repeated is None:
            return None
        return int(repeated)

    @repeated.setter
    def repeated(self, repeated: int | None) -> None:
        self._set_repeated(repeated)
        # update cache
        current: Element = self
        while True:
            # look for Table, parent may be group of rows
            upper = current.parent
            if not upper:
                # lonely column
                return
            # parent may be group of rows, not table
            if upper.tag == "table:table":
                break
            current = upper

    @property
    def style(self) -> str | None:
        """Get or set the style of the column itself.

        Returns:
            str or None: The name of the style applied to the column.
        """
        return self.get_attribute_string("table:style-name")

    @style.setter
    def style(self, style: str | Style | None) -> None:
        self.set_style_attribute("table:style-name", style)

_tag class-attribute instance-attribute

_tag = 'table:table-column'

clone property

clone: Column

Return a clone of the column.

default_cell_style property writable

default_cell_style: str | None

Get or set the default cell style for the column.

Returns:

Type Description
str | None

str or None: The name of the default cell style, or None if not set.

repeated property writable

repeated: int | None

Get or set the number of times the column is repeated.

This property is typically None when using the higher-level table API.

Returns:

Type Description
int | None

int or None: The number of repetitions, or None if not repeated.

style property writable

style: str | None

Get or set the style of the column itself.

Returns:

Type Description
str | None

str or None: The name of the style applied to the column.

x instance-attribute

x: int | None = None

__init__

__init__(
    default_cell_style: str | None = None,
    repeated: int | None = None,
    style: str | None = None,
    **kwargs: Any,
) -> None

A Column of a table, “table:table-column”.

This constructor creates a column element with an optional style. The default cell style can be set for the entire column. If the properties apply to multiple columns, the number of repeated columns can be specified.

Columns do not contain cells themselves, but only styling information.

Note

It is generally not necessary to create columns by hand; the higher-level Table API should be used instead.

Parameters:

Name Type Description Default
default_cell_style str | None

The name of the default style to apply to cells in this column.

None
repeated int | None

The number of times this column should be repeated. Must be greater than 1.

None
style str | None

The name of the style to apply to the column itself.

None
Source code in odfdo/column.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
def __init__(
    self,
    default_cell_style: str | None = None,
    repeated: int | None = None,
    style: str | None = None,
    **kwargs: Any,
) -> None:
    """A Column of a table, "table:table-column".

    This constructor creates a column element with an optional style.
    The default cell style can be set for the entire column. If the
    properties apply to multiple columns, the number of repeated columns
    can be specified.

    Columns do not contain cells themselves, but only styling information.

    Note:
        It is generally not necessary to create columns by hand; the
        higher-level Table API should be used instead.

    Args:
        default_cell_style: The name of the
            default style to apply to cells in this column.
        repeated: The number of times this column
            should be repeated. Must be greater than 1.
        style: The name of the style to apply to
            the column itself.
    """
    super().__init__(**kwargs)
    self.x: int | None = None
    if self._do_init:
        if default_cell_style:
            self.default_cell_style = default_cell_style
        if repeated and repeated > 1:
            self.repeated = repeated
        if style:
            self.style = style

__repr__

__repr__() -> str
Source code in odfdo/column.py
80
81
def __repr__(self) -> str:
    return f"<{self.__class__.__name__} x={self.x}>"

_set_repeated

_set_repeated(repeated: int | None) -> None

Set the number of times the column is repeated.

This is an internal method that sets the ‘table:number-columns-repeated’ attribute without triggering cache updates. Use None to remove the attribute.

Parameters:

Name Type Description Default
repeated int | None

The number of times the column should be repeated. If None or less than 2, the attribute is removed.

required
Source code in odfdo/column.py
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
def _set_repeated(self, repeated: int | None) -> None:
    """Set the number of times the column is repeated.

    This is an internal method that sets the 'table:number-columns-repeated'
    attribute without triggering cache updates. Use None to remove the
    attribute.

    Args:
        repeated: The number of times the column should be
            repeated. If None or less than 2, the attribute is removed.
    """
    if repeated is None or repeated < 2:
        with contextlib.suppress(KeyError):
            self.del_attribute("table:number-columns-repeated")
        return
    self.set_attribute("table:number-columns-repeated", str(repeated))

get_default_cell_style

get_default_cell_style() -> str | None

Get the default cell style for the column.

(See also the default_cell_style property.)

Returns:

Type Description
str | None

str or None: The name of the default cell style, or None if not set.

Source code in odfdo/column.py
90
91
92
93
94
95
96
97
98
def get_default_cell_style(self) -> str | None:
    """Get the default cell style for the column.

    (See also the `default_cell_style` property.)

    Returns:
        str or None: The name of the default cell style, or None if not set.
    """
    return self.get_attribute_string("table:default-cell-style-name")

set_default_cell_style

set_default_cell_style(style: Style | str | None) -> None

Set the default cell style for the column.

(See also the default_cell_style property.)

Parameters:

Name Type Description Default
style Style | str | None

The style to apply. Can be a Style object, the name of a style, or None to remove the style.

required
Source code in odfdo/column.py
100
101
102
103
104
105
106
107
108
109
def set_default_cell_style(self, style: Style | str | None) -> None:
    """Set the default cell style for the column.

    (See also the `default_cell_style` property.)

    Args:
        style: The style to apply. Can be a Style
            object, the name of a style, or None to remove the style.
    """
    self.set_style_attribute("table:default-cell-style-name", style)