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

Skip to content

Commit 254d2ef

Browse files
revossen-asmlSteve Canny
authored andcommitted
tbl: add _Row.height setter
1 parent 6b6ef6b commit 254d2ef

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

docx/oxml/table.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ def trHeight_val(self):
8787
return None
8888
return trPr.trHeight_val
8989

90+
@trHeight_val.setter
91+
def trHeight_val(self, value):
92+
trPr = self.get_or_add_trPr()
93+
trPr.trHeight_val = value
94+
9095
def _insert_tblPrEx(self, tblPrEx):
9196
self.insert(0, tblPrEx)
9297

@@ -852,6 +857,13 @@ def trHeight_val(self):
852857
return None
853858
return trHeight.val
854859

860+
@trHeight_val.setter
861+
def trHeight_val(self, value):
862+
if value is None and self.trHeight is None:
863+
return
864+
trHeight = self.get_or_add_trHeight()
865+
trHeight.val = value
866+
855867

856868
class CT_VMerge(BaseOxmlElement):
857869
"""

docx/table.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,10 @@ def height(self):
391391
"""
392392
return self._tr.trHeight_val
393393

394+
@height.setter
395+
def height(self, value):
396+
self._tr.trHeight_val = value
397+
394398
@property
395399
def height_rule(self):
396400
"""

features/tbl-row-props.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ Feature: Get and set table row properties
3939
| 3 inches | 2743200 |
4040

4141

42-
@wip
4342
Scenario Outline: Set row height
4443
Given a table row having height of <state>
4544
When I assign <value> to row.height

tests/test_table.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,11 @@ def it_knows_its_height(self, height_get_fixture):
657657
row, expected_height = height_get_fixture
658658
assert row.height == expected_height
659659

660+
def it_can_change_its_height(self, height_set_fixture):
661+
row, value, expected_xml = height_set_fixture
662+
row.height = value
663+
assert row._tr.xml == expected_xml
664+
660665
def it_knows_its_height_rule(self, height_rule_get_fixture):
661666
row, expected_rule = height_rule_get_fixture
662667
assert row.height_rule == expected_rule
@@ -702,6 +707,27 @@ def height_get_fixture(self, request):
702707
row = _Row(element(tr_cxml), None)
703708
return row, expected_height
704709

710+
@pytest.fixture(params=[
711+
('w:tr', Inches(1),
712+
'w:tr/w:trPr/w:trHeight{w:val=1440}'),
713+
('w:tr/w:trPr', Inches(1),
714+
'w:tr/w:trPr/w:trHeight{w:val=1440}'),
715+
('w:tr/w:trPr/w:trHeight', Inches(1),
716+
'w:tr/w:trPr/w:trHeight{w:val=1440}'),
717+
('w:tr/w:trPr/w:trHeight{w:val=1440}', Inches(2),
718+
'w:tr/w:trPr/w:trHeight{w:val=2880}'),
719+
('w:tr/w:trPr/w:trHeight{w:val=2880}', None,
720+
'w:tr/w:trPr/w:trHeight'),
721+
('w:tr', None, 'w:tr/w:trPr'),
722+
('w:tr/w:trPr', None, 'w:tr/w:trPr'),
723+
('w:tr/w:trPr/w:trHeight', None, 'w:tr/w:trPr/w:trHeight'),
724+
])
725+
def height_set_fixture(self, request):
726+
tr_cxml, new_value, expected_cxml = request.param
727+
row = _Row(element(tr_cxml), None)
728+
expected_xml = xml(expected_cxml)
729+
return row, new_value, expected_xml
730+
705731
@pytest.fixture(params=[
706732
('w:tr', None),
707733
('w:tr/w:trPr', None),

0 commit comments

Comments
 (0)