Row
Row class for “table:table-row” tag.
Classes:
| Name | Description |
|---|---|
Row |
A row of a table, “table:table-row”. |
_XPATH_CELL
module-attribute
_XPATH_CELL = xpath_compile(
"(table:table-cell|table:covered-table-cell)"
)
Row
Bases: Element
A row of a table, “table:table-row”.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
The number of cells to create in the row. |
None
|
repeated
|
int
|
The number of times the row is repeated. |
None
|
style
|
str
|
The style name for the row. |
None
|
Methods:
| Name | Description |
|---|---|
__init__ |
Create a Row, “table:table-row”, optionally filled with “width” |
__repr__ |
|
append_cell |
Append a cell at the end of the row. Repeated cells are accepted. |
clear |
Remove text, children and attributes from the Row. |
delete_cell |
Delete the cell at the given position “x”. Alphabetical positions |
extend_cells |
Extend the row with a list of cells. |
force_width |
Change the repeated property of the last cell of the row to comply |
get_cell |
Get the cell at position “x”. Alphabetical positions like “D” are |
get_cells |
Get the list of cells matching the criteria. |
get_elements |
Get a list of elements matching the XPath query. |
get_sub_elements |
Shortcut to get the Elements inside cells in this row. |
get_value |
Shortcut to get the value of the cell at position “x”. |
get_values |
Shortcut to get the cell values in this row. |
insert_cell |
Insert a cell at position “x”. If no cell is given, an empty one is |
is_empty |
Return whether every cell in the row is empty. |
iter_cells |
Yields Cell elements, expanding repetitions. |
last_cell |
Return the last cell of the row. |
minimized_width |
Return the length of the row if the last repeated sequence is |
rstrip |
Remove empty cells at the right of the row, in-place. |
set_cell |
Set the cell at position “x”. Alphabetical positions like “D” are |
set_cells |
Set the cells in the row, from the ‘start’ column. This method does |
set_value |
Shortcut to set the value of the cell at position “x”. |
set_values |
Shortcut to set the value of cells in the row, from the ‘start’ |
Attributes:
| Name | Type | Description |
|---|---|---|
append |
|
|
cells |
list[Cell]
|
Get the list of all cells. |
clone |
Row
|
Return a copy of the row. |
repeated |
int | None
|
Get / set the number of times the row is repeated. |
style |
str | None
|
Get /set the style of the row itself. |
traverse |
|
|
width |
int
|
Get the number of expected cells in the row, including repetitions. |
y |
|
Source code in odfdo/row.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 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 | |
_append
class-attribute
instance-attribute
_append = append
_row_cache
instance-attribute
_row_cache = RowCache()
_table_cache
instance-attribute
_table_cache = TableCache()
_tag
class-attribute
instance-attribute
_tag = 'table:table-row'
append
class-attribute
instance-attribute
append = append_cell
cells
property
cells: list[Cell]
clone
property
clone: Row
Return a copy of the row.
repeated
property
writable
repeated: int | None
Get / set the number of times the row is repeated.
Always None when using the table API.
Returns:
| Type | Description |
|---|---|
int | None
|
int | None: The number of repetitions. |
style
property
writable
style: str | None
Get /set the style of the row itself.
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: The style name. |
traverse
class-attribute
instance-attribute
traverse = iter_cells
width
property
width: int
Get the number of expected cells in the row, including repetitions.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The width of the row. |
y
instance-attribute
y = None
__init__
__init__(
width: int | None = None,
repeated: int | None = None,
style: str | None = None,
**kwargs: Any,
) -> None
Create a Row, “table:table-row”, optionally filled with “width” number of cells.
Rows contain cells, their number determine the number of columns.
You don’t generally have to create rows by hand, use the Table API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int | None
|
The number of cells to create in the row. |
None
|
repeated
|
int | None
|
The number of times the row is repeated. |
None
|
style
|
str | None
|
The style name for the row. |
None
|
Source code in odfdo/row.py
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 | |
__repr__
__repr__() -> str
Source code in odfdo/row.py
97 98 | |
_compute_row_cache
_compute_row_cache() -> None
Source code in odfdo/row.py
156 157 158 159 160 | |
_copy_cache
_copy_cache(cache: tuple) -> None
Copy cache when cloning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache
|
tuple
|
The cache to copy. |
required |
Source code in odfdo/row.py
122 123 124 125 126 127 128 129 130 | |
_current_length
_current_length() -> int
Return the current estimated length of the row.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The length of the row. |
Source code in odfdo/row.py
753 754 755 756 757 758 759 760 761 762 763 764 765 | |
_get_cell2
_get_cell2(x: int, clone: bool = True) -> Cell | None
Source code in odfdo/row.py
351 352 353 354 355 356 357 358 359 | |
_get_cell2_base
_get_cell2_base(x: int) -> Cell | None
Source code in odfdo/row.py
361 362 363 364 365 366 367 368 369 370 371 | |
_get_cells
_get_cells() -> list[Cell]
Source code in odfdo/row.py
138 139 | |
_set_repeated
_set_repeated(repeated: int | None) -> None
Set the number of times the row is repeated.
Internal use only. Without changing cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repeated
|
int | None
|
The number of repetitions. |
required |
Source code in odfdo/row.py
173 174 175 176 177 178 179 180 181 182 183 184 185 | |
_translate_row_coordinates
_translate_row_coordinates(
coord: tuple | list | str,
) -> tuple[int | None, int | None]
Source code in odfdo/row.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
_translate_x_from_any
_translate_x_from_any(x: str | int) -> int
Source code in odfdo/row.py
241 242 | |
_yield_odf_cells
_yield_odf_cells() -> Iterator[Cell]
Source code in odfdo/row.py
244 245 246 247 248 249 250 251 252 | |
append_cell
append_cell(
cell: Cell | None = None,
clone: bool = True,
_repeated: int | None = None,
) -> Cell
Append a cell at the end of the row. Repeated cells are accepted. If no cell is given, an empty one is created.
Do not use when working on a table, use Table.append_cell().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cell
|
Cell | None
|
The cell to append. |
None
|
clone
|
bool
|
Whether to clone the cell before appending it. |
True
|
_repeated
|
int | None
|
The repeated value of the cell. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Cell |
Cell
|
The cell that was appended. |
Source code in odfdo/row.py
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 | |
clear
clear() -> None
Remove text, children and attributes from the Row.
Source code in odfdo/row.py
132 133 134 135 136 | |
delete_cell
delete_cell(x: int | str) -> None
Delete the cell at the given position “x”. Alphabetical positions like “D” are also accepted.
Cells on the right will be shifted to the left. In a table, other rows remain unaffected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
int | str
|
The column index or name. |
required |
Source code in odfdo/row.py
574 575 576 577 578 579 580 581 582 583 584 585 586 587 | |
extend_cells
extend_cells(cells: Iterable[Cell] | None = None) -> None
Extend the row with a list of cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cells
|
Iterable[Cell] | None
|
The cells to append. |
None
|
Source code in odfdo/row.py
528 529 530 531 532 533 534 535 536 537 | |
force_width
force_width(width: int) -> None
Change the repeated property of the last cell of the row to comply with the required max width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
The target width. |
required |
Source code in odfdo/row.py
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 | |
get_cell
get_cell(x: int, clone: bool = True) -> Cell | None
Get the cell at position “x”. Alphabetical positions like “D” are also accepted.
A copy is returned, so changes will not affect the document.
Use set_cell to apply changes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
int
|
The column index or name. |
required |
clone
|
bool
|
Whether to return a copy of the cell. |
True
|
Returns:
| Type | Description |
|---|---|
Cell | None
|
Cell | None: The cell at the given position. |
Source code in odfdo/row.py
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
get_cells
get_cells(
coord: str | tuple | None = None,
style: str | None = None,
content: str | None = None,
cell_type: str | None = None,
) -> list[Cell]
Get the list of cells matching the criteria.
Filter by cell_type, with cell_type ‘all’ will retrieve cells of any type, aka non empty cells.
Filter by coordinates will retrieve the amount of cells defined by ‘coord’, minus the other filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coord
|
str | tuple | None
|
The coordinates of the cells. |
None
|
style
|
str | None
|
The style name to filter by. |
None
|
content
|
str | None
|
A regex to match in the cell content. |
None
|
cell_type
|
str | None
|
The type of the cell. Can be ‘boolean’, ‘float’, ‘date’, ‘string’, ‘time’, ‘currency’, ‘percentage’ or ‘all’. |
None
|
Returns:
| Type | Description |
|---|---|
list[Cell]
|
list[Cell]: A list of matching cells. |
Source code in odfdo/row.py
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 | |
get_elements
get_elements(xpath_query: XPath | str) -> list[Element]
Get a list of elements matching the XPath query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xpath_query
|
XPath | str
|
The XPath query. |
required |
Returns:
| Type | Description |
|---|---|
list[Element]
|
list[Element]: A list of matching elements. |
Source code in odfdo/row.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
get_sub_elements
get_sub_elements() -> list[Any]
Shortcut to get the Elements inside cells in this row.
Missing values are replaced by None. Cell type should be always ‘string’ when using this method, the length of the list is equal to the length of the row.
Returns:
| Type | Description |
|---|---|
list[Any]
|
list[Any]: A list of elements. |
Source code in odfdo/row.py
647 648 649 650 651 652 653 654 655 656 657 658 659 | |
get_value
get_value(
x: int | str, get_type: bool = False
) -> Any | tuple[Any, str]
Shortcut to get the value of the cell at position “x”.
If get_type is True, returns a tuple (value, ODF type).
If the cell is empty, returns None or (None, None).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
int | str
|
The column index or name. |
required |
get_type
|
bool
|
Whether to return the ODF type of the value. |
False
|
Returns:
| Type | Description |
|---|---|
Any | tuple[Any, str]
|
Any | tuple[Any, str]: The value of the cell, or a tuple (value, type). |
Source code in odfdo/row.py
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 | |
get_values
get_values(
coord: str | tuple | None = None,
cell_type: str | None = None,
complete: bool = False,
get_type: bool = False,
) -> list[Any | tuple[Any, Any]]
Shortcut to get the cell values in this row.
- Filter by
cell_type: with ‘all’ will retrieve cells of any type (non-empty). - If
cell_typeis used andcompleteis True, missing values are replaced by None. - If
cell_typeis None,completeis always True:get_values()returns None for each empty cell, the length of the list is equal to the length of the row (depending on coordinates use). - If
get_typeis True, returns a tuple (value, ODF type of value), or (None, None) for empty cells ifcompleteis True. - Filter by
coordwill retrieve the amount of cells defined by coordinates with None for empty cells, except when usingcell_type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coord
|
str | tuple | None
|
Coordinates in the row. |
None
|
cell_type
|
str | None
|
Type of cell to filter by. Can be ‘boolean’, ‘float’, ‘date’, ‘string’, ‘time’, ‘currency’, ‘percentage’ or ‘all’. |
None
|
complete
|
bool
|
Whether to include empty cells as None. |
False
|
get_type
|
bool
|
Whether to return the ODF type of the value. |
False
|
Returns:
| Type | Description |
|---|---|
list[Any | tuple[Any, Any]]
|
list[Any | tuple[Any, Any]]: A list of values, or a list of (value, type) tuples. |
Source code in odfdo/row.py
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 | |
insert_cell
insert_cell(
x: int | str,
cell: Cell | None = None,
clone: bool = True,
) -> Cell
Insert a cell at position “x”. If no cell is given, an empty one is created.
Alphabetical positions like “D” are also accepted.
Do not use when working on a table, use Table.insert_cell().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
int | str
|
The column index or name. |
required |
cell
|
Cell | None
|
The cell to insert. |
None
|
clone
|
bool
|
Whether to clone the cell before inserting it. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
Cell |
Cell
|
The cell that was inserted. |
Source code in odfdo/row.py
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 | |
is_empty
is_empty(aggressive: bool = False) -> bool
Return whether every cell in the row is empty.
An empty cell has no value (or the value evaluates to False) and no
style. If aggressive is True, empty cells with style are considered
empty.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aggressive
|
bool
|
If True, ignores cell style. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the row is empty, False otherwise. |
Source code in odfdo/row.py
819 820 821 822 823 824 825 826 827 828 829 830 831 832 | |
iter_cells
iter_cells(
start: int | None = None, end: int | None = None
) -> Iterator[Cell]
Yields Cell elements, expanding repetitions.
This method produces individual Cell objects. The yielded
Cell are copies; use set_cell() to apply changes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
int | None
|
The starting cell index (0-based). Defaults to 0. |
None
|
end
|
int | None
|
The ending cell index (inclusive). Defaults to 2**32. |
None
|
Yields:
| Name | Type | Description |
|---|---|---|
Cell |
Cell
|
The next Cell element in the specified range.. |
Source code in odfdo/row.py
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 | |
last_cell
last_cell() -> Cell | None
Return the last cell of the row.
Returns:
| Type | Description |
|---|---|
Cell | None
|
Cell or None: The last cell, or None if the row is empty. |
Source code in odfdo/row.py
789 790 791 792 793 794 795 796 797 798 | |
minimized_width
minimized_width() -> int
Return the length of the row if the last repeated sequence is reduced to one.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The minimized width of the row. |
Source code in odfdo/row.py
767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 | |
rstrip
rstrip(aggressive: bool = False) -> None
Remove empty cells at the right of the row, in-place.
An empty cell has no value but can have style. If aggressive is
True, style is ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aggressive
|
bool
|
If True, ignores cell style. |
False
|
Source code in odfdo/row.py
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 | |
set_cell
set_cell(
x: int | str,
cell: Cell | None = None,
clone: bool = True,
) -> Cell
Set the cell at position “x”. Alphabetical positions like “D” are also accepted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
int | str
|
The column index or name. |
required |
cell
|
Cell | None
|
The cell to set. If None, an empty cell is created. |
None
|
clone
|
bool
|
Whether to clone the cell before setting it. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
Cell |
Cell
|
The cell that was set. |
Source code in odfdo/row.py
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 | |
set_cells
set_cells(
cells: list[Cell] | tuple[Cell] | None = None,
start: int | str = 0,
clone: bool = True,
) -> None
Set the cells in the row, from the ‘start’ column. This method does not clear the row, use row.clear() before to start with an empty row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cells
|
list[Cell] | tuple[Cell] | None
|
The cells to set. |
None
|
start
|
int | str
|
The starting column index or name. |
0
|
clone
|
bool
|
Whether to clone the cells before setting them. |
True
|
Source code in odfdo/row.py
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 | |
set_value
set_value(
x: int | str,
value: Any,
style: str | None = None,
cell_type: str | None = None,
currency: str | None = None,
) -> None
Shortcut to set the value of the cell at position “x”.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
int | str
|
The column index or name. |
required |
value
|
Any
|
The value to set. |
required |
style
|
str | None
|
The style to apply to the cell. |
None
|
cell_type
|
str | None
|
The type of the cell. Can be ‘boolean’, ‘currency’, ‘date’, ‘float’, ‘string’, ‘time’, ‘currency’ or ‘percentage’. |
None
|
currency
|
str | None
|
The currency symbol if the type is ‘currency’. |
None
|
Source code in odfdo/row.py
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 | |
set_values
set_values(
values: list[Any],
start: int | str = 0,
style: str | None = None,
cell_type: str | None = None,
currency: str | None = None,
) -> None
Shortcut to set the value of cells in the row, from the ‘start’ column with values. This method does not clear the row, use row.clear() before to start with an empty row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
list[Any]
|
A list of values to set. |
required |
start
|
int | str
|
The starting column index or name. |
0
|
style
|
str | None
|
The style to apply to the cells. |
None
|
cell_type
|
str | None
|
The type of the cells. Can be ‘boolean’, ‘float’, ‘date’, ‘string’, ‘time’, ‘currency’ or ‘percentage’. |
None
|
currency
|
str | None
|
The currency symbol if the type is ‘currency’. |
None
|
Source code in odfdo/row.py
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 | |