Cell
Cell class for “table:table-cell” and “table:covered-table-cell” tags.
Classes:
| Name | Description |
|---|---|
Cell |
A cell of a table, “table:table-cell” and “table:covered-table-cell”. |
_bool
module-attribute
_bool = bool
_float
module-attribute
_float = float
_int
module-attribute
_int = int
Cell
Bases: ListMixin, TocMixin, SectionMixin, AnnotationMixin, ElementTyped
A cell of a table, “table:table-cell” and “table:covered-table-cell”.
Methods:
| Name | Description |
|---|---|
__init__ |
Create a cell element. |
__repr__ |
|
is_covered |
Check if the cell is covered. |
is_empty |
Check if the cell is empty. |
is_spanned |
Check if the cell spans over multiple cells. |
set_value |
Set the cell state from a Python value. |
span_area |
Return the dimensions of the area spanned by the cell. |
Attributes:
| Name | Type | Description |
|---|---|---|
bool |
_bool
|
Get or set the value of the cell as a boolean. |
clone |
Cell
|
|
currency |
str | None
|
Get or set the currency used for monetary values. |
date |
date
|
Get or set the value of the cell as a date. |
datetime |
datetime
|
Get or set the value of the cell as a datetime. |
decimal |
Decimal
|
Get or set the value of the cell as a Decimal (or 0.0). |
duration |
timedelta
|
Get or set the value of the cell as a duration (Python timedelta). |
float |
_float
|
Get or set the value of the cell as a float (or 0.0). |
formula |
str | None
|
Get or set the formula of the cell. |
int |
_int
|
Get or set the value of the cell as an integer (or 0). |
repeated |
_int | None
|
Get or set the number of times the cell is repeated across columns. |
string |
str
|
Get or set the value of the cell as a string (or ‘’). |
style |
str | None
|
Get or set the style name of the cell. |
type |
str | None
|
Get or set the type of the cell. |
value |
str | _bool | _int | _float | Decimal | date | datetime | timedelta | None
|
Get or set the value of the cell. |
x |
int | None
|
|
y |
int | None
|
|
Source code in odfdo/cell.py
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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 | |
_bool_string
property
_bool_string: str
Return the boolean value as a string ‘0’ or ‘1’.
_is_spanned
class-attribute
instance-attribute
_is_spanned = is_spanned
_tag
class-attribute
instance-attribute
_tag = 'table:table-cell'
bool
property
writable
bool: _bool
Get or set the value of the cell as a boolean.
When setting the value, force the cell type to “boolean”.
clone
property
clone: Cell
currency
property
writable
currency: str | None
Get or set the currency used for monetary values.
Returns:
| Type | Description |
|---|---|
str | None
|
str or None: The currency code (e.g., “EUR”, “USD”). |
date
property
writable
date: date
Get or set the value of the cell as a date.
When setting the value, force the cell type to “date”.
datetime
property
writable
datetime: datetime
Get or set the value of the cell as a datetime.
When setting the value, force the cell type to “date”.
decimal
property
writable
decimal: Decimal
Get or set the value of the cell as a Decimal (or 0.0).
When setting the value, force the cell type to “float”.
duration
property
writable
duration: timedelta
Get or set the value of the cell as a duration (Python timedelta).
When setting the value, force the cell type to “time”.
float
property
writable
float: _float
Get or set the value of the cell as a float (or 0.0).
When setting the value, force the cell type to “float”.
formula
property
writable
formula: str | None
Get or set the formula of the cell.
The formula is stored as a string and is not interpreted by odfdo.
Returns:
| Type | Description |
|---|---|
str | None
|
str or None: The formula string, or None if no formula is defined. |
int
property
writable
int: _int
Get or set the value of the cell as an integer (or 0).
When setting the value, force the cell type to “float”.
repeated
property
writable
repeated: _int | None
Get or set the number of times the cell is repeated across columns.
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. |
string
property
writable
string: str
Get or set the value of the cell as a string (or ‘’).
When setting the value, force the cell type to “string”.
style
property
writable
style: str | None
Get or set the style name of the cell.
Returns:
| Type | Description |
|---|---|
str | None
|
str or None: The name of the style applied to the cell. |
type
property
writable
type: str | None
Get or set the type of the cell.
Valid types include ‘boolean’, ‘float’, ‘date’, ‘string’, or ‘time’.
Returns:
| Type | Description |
|---|---|
str | None
|
str or None: The type of the cell’s value. |
value
property
writable
value: (
str
| _bool
| _int
| _float
| Decimal
| date
| datetime
| timedelta
| None
)
Get or set the value of the cell.
When getting, the type is inferred from the ‘office:value-type’ attribute. When setting, the type of the provided Python value determines the ‘office:value-type’ of the cell.
Note: the cell content is only cleared when using “cell.value = None”. To ensure an absolute empty cell, use cell.clear() that will remove all componants (style, span property, xml:id, …).
Warning
- For
date,datetime, andtimedelta, a default text value is automatically generated. - For boolean types, the text value will be either ‘True’ or ‘False’.
- For numeric types, the return value is typically
Decimalorint. Use thefloat,decimal, orintproperties to force a specific return type. - To customize the text representation, use the
set_value()method. - To change the string representation of the cell without changing the cell type, use the low level property cell.text
Returns:
| Type | Description |
|---|---|
str | _bool | _int | _float | Decimal | date | datetime | timedelta | None
|
Union[str, bool, int, float, Decimal, date, datetime, timedelta, None]: The value of the cell in its appropriate Python type. |
x
instance-attribute
x: int | None = None
y
instance-attribute
y: int | None = None
__init__
__init__(
value: Any = None,
text: str | None = None,
cell_type: str | None = None,
currency: str | None = None,
formula: str | None = None,
repeated: _int | None = None,
style: str | None = None,
**kwargs: Any,
) -> None
Create a cell element.
A cell in a table, represented by “table:table-cell”. This constructor creates a cell element containing the given value. The textual representation is automatically formatted but can be provided explicitly. The cell type can be deduced automatically, unless the number is a percentage or currency. If the cell type is “currency”, the currency must be specified. The cell can also be repeated across a given number of columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
The Python value to set for the cell. Can be a boolean, int, float, Decimal, date, datetime, str, or timedelta. |
None
|
text
|
str | None
|
The textual representation of the cell’s content. If not provided, it is generated from the value. |
None
|
cell_type
|
str | None
|
The explicit type of the cell. Valid options include ‘boolean’, ‘currency’, ‘date’, ‘float’, ‘percentage’, ‘string’, or ‘time’. If not provided, it’s guessed from the value. |
None
|
currency
|
str | None
|
A three-letter currency code (e.g., “EUR”, “USD”) if the cell_type is ‘currency’. |
None
|
formula
|
str | None
|
The formula for the cell. |
None
|
repeated
|
_int | None
|
The number of times this cell should be repeated across columns. Must be greater than 1. |
None
|
style
|
str | None
|
The name of the style to apply to the cell. |
None
|
Source code in odfdo/cell.py
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 | |
__repr__
__repr__() -> str
Source code in odfdo/cell.py
109 110 | |
_set_float_value_str
_set_float_value_str(value_str: str) -> None
Source code in odfdo/cell.py
243 244 245 246 247 248 249 250 251 252 253 | |
_set_repeated
_set_repeated(repeated: _int | None) -> None
Set the number of times the cell is repeated.
Internal method that sets the ‘table:number-columns-repeated’ attribute,
or removes it if repeated is None or less than 2, without
triggering cache updates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repeated
|
_int | None
|
The number of times the cell should be repeated. If None or less than 2, the attribute is removed. |
required |
Source code in odfdo/cell.py
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 | |
is_covered
is_covered() -> _bool
Check if the cell is covered.
A covered cell is represented by the “table:covered-table-cell” tag.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
_bool
|
True if the cell is covered, False otherwise. |
Source code in odfdo/cell.py
609 610 611 612 613 614 615 616 617 | |
is_empty
is_empty(aggressive: _bool = False) -> _bool
Check if the cell is empty.
An empty cell has no value, no children, is not covered, and is not spanned. By default, cells with a style are not considered empty.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aggressive
|
_bool
|
If True, a cell with a style but no content is also considered empty. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
_bool
|
True if the cell is empty, False otherwise. |
Source code in odfdo/cell.py
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 | |
is_spanned
is_spanned(covered: _bool = True) -> _bool
Check if the cell spans over multiple cells.
A cell is considered spanned if it has ‘table:number-columns-spanned’ or ‘table:number-rows-spanned’ attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
covered
|
_bool
|
If True, covered cells (those with the “table:covered-table-cell” tag) are also considered spanned. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
_bool
|
True if the cell is spanned, False otherwise. |
Source code in odfdo/cell.py
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 | |
set_value
set_value(
value: str
| bytes
| _float
| _int
| Decimal
| _bool
| datetime
| date
| timedelta
| None,
text: str | None = None,
cell_type: str | None = None,
currency: str | None = None,
formula: str | None = None,
) -> None
Set the cell state from a Python value.
The text parameter defines how the cell is displayed.
The cell type is guessed unless explicitly provided.
For monetary values, the name of the currency must be provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | bytes | _float | _int | Decimal | _bool | datetime | date | timedelta | None
|
The Python value to assign to the cell. |
required |
text
|
str | None
|
The explicit textual representation of the
cell’s content. If None, it is derived from the |
None
|
cell_type
|
str | None
|
The explicit type of the cell’s value. Can be ‘boolean’, ‘float’, ‘date’, ‘string’, ‘time’, ‘currency’, or ‘percentage’. |
None
|
currency
|
str | None
|
A string representing the currency, e.g.,
“EUR” or “USD”, required if |
None
|
formula
|
str | None
|
The formula to set for the cell. |
None
|
Source code in odfdo/cell.py
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
span_area
span_area() -> tuple[_int, _int]
Return the dimensions of the area spanned by the cell.
Returns a tuple (nb_columns, nb_rows) indicating how many columns
and rows the cell spans. If the cell is not spanned, it returns (0, 0).
Returns:
| Type | Description |
|---|---|
tuple[_int, _int]
|
tuple[int, int]: A tuple containing the number of spanned columns and rows. |
Source code in odfdo/cell.py
643 644 645 646 647 648 649 650 651 652 653 654 655 | |