Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6b6ef6b

Browse files
revossen-asmlSteve Canny
authored andcommitted
tbl: add _Row.height getter
1 parent 4f12bde commit 6b6ef6b

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

docx/oxml/table.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ def trHeight_hRule(self, value):
7676
trPr = self.get_or_add_trPr()
7777
trPr.trHeight_hRule = value
7878

79+
@property
80+
def trHeight_val(self):
81+
"""
82+
Return the value of `w:trPr/w:trHeight@w:val`, or |None| if not
83+
present.
84+
"""
85+
trPr = self.trPr
86+
if trPr is None:
87+
return None
88+
return trPr.trHeight_val
89+
7990
def _insert_tblPrEx(self, tblPrEx):
8091
self.insert(0, tblPrEx)
8192

@@ -831,6 +842,16 @@ def trHeight_hRule(self, value):
831842
trHeight = self.get_or_add_trHeight()
832843
trHeight.hRule = value
833844

845+
@property
846+
def trHeight_val(self):
847+
"""
848+
Return the value of `w:trHeight@w:val`, or |None| if not present.
849+
"""
850+
trHeight = self.trHeight
851+
if trHeight is None:
852+
return None
853+
return trHeight.val
854+
834855

835856
class CT_VMerge(BaseOxmlElement):
836857
"""

docx/table.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ class _Row(Parented):
374374
"""
375375
def __init__(self, tr, parent):
376376
super(_Row, self).__init__(parent)
377-
self._tr = tr
377+
self._tr = self._element = tr
378378

379379
@property
380380
def cells(self):
@@ -383,6 +383,14 @@ def cells(self):
383383
"""
384384
return tuple(self.table.row_cells(self._index))
385385

386+
@property
387+
def height(self):
388+
"""
389+
Return a |Length| object representing the height of this cell, or
390+
|None| if no explicit height is set.
391+
"""
392+
return self._tr.trHeight_val
393+
386394
@property
387395
def height_rule(self):
388396
"""

features/tbl-row-props.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ Feature: Get and set table row properties
2828
| no explicit setting | None |
2929

3030

31-
@wip
3231
Scenario Outline: Get Row.height
3332
Given a table row having height of <state>
3433
Then row.height is <value>

tests/test_table.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,10 @@ def table_(self, request):
653653

654654
class Describe_Row(object):
655655

656+
def it_knows_its_height(self, height_get_fixture):
657+
row, expected_height = height_get_fixture
658+
assert row.height == expected_height
659+
656660
def it_knows_its_height_rule(self, height_rule_get_fixture):
657661
row, expected_rule = height_rule_get_fixture
658662
assert row.height_rule == expected_rule
@@ -686,6 +690,18 @@ def cells_fixture(self, _index_, table_prop_, table_):
686690
table_.row_cells.return_value = list(expected_cells)
687691
return row, row_idx, expected_cells
688692

693+
@pytest.fixture(params=[
694+
('w:tr', None),
695+
('w:tr/w:trPr', None),
696+
('w:tr/w:trPr/w:trHeight', None),
697+
('w:tr/w:trPr/w:trHeight{w:val=0}', 0),
698+
('w:tr/w:trPr/w:trHeight{w:val=1440}', 914400),
699+
])
700+
def height_get_fixture(self, request):
701+
tr_cxml, expected_height = request.param
702+
row = _Row(element(tr_cxml), None)
703+
return row, expected_height
704+
689705
@pytest.fixture(params=[
690706
('w:tr', None),
691707
('w:tr/w:trPr', None),

0 commit comments

Comments
 (0)