1010from .ns import nsdecls
1111from ..shared import Emu , Twips
1212from .simpletypes import (
13- ST_TblLayoutType , ST_TblWidth , ST_TwipsMeasure , XsdInt
13+ ST_Merge , ST_TblLayoutType , ST_TblWidth , ST_TwipsMeasure , XsdInt
1414)
1515from .xmlchemy import (
1616 BaseOxmlElement , OneAndOnlyOne , OneOrMore , OptionalAttribute ,
@@ -44,6 +44,16 @@ class CT_Tbl(BaseOxmlElement):
4444 tblGrid = OneAndOnlyOne ('w:tblGrid' )
4545 tr = ZeroOrMore ('w:tr' )
4646
47+ def iter_tcs (self ):
48+ """
49+ Generate each of the `w:tc` elements in this table, left to right and
50+ top to bottom. Each cell in the first row is generated, followed by
51+ each cell in the second row, etc.
52+ """
53+ for tr in self .tr_lst :
54+ for tc in tr .tc_lst :
55+ yield tc
56+
4757 @classmethod
4858 def new (cls ):
4959 """
@@ -182,18 +192,6 @@ class CT_Tc(BaseOxmlElement):
182192 p = OneOrMore ('w:p' )
183193 tbl = OneOrMore ('w:tbl' )
184194
185- def _insert_tcPr (self , tcPr ):
186- """
187- ``tcPr`` has a bunch of successors, but it comes first if it appears,
188- so just overriding and using insert(0, ...) rather than spelling out
189- successors.
190- """
191- self .insert (0 , tcPr )
192- return tcPr
193-
194- def _new_tbl (self ):
195- return CT_Tbl .new ()
196-
197195 def clear_content (self ):
198196 """
199197 Remove all content child elements, preserving the ``<w:tcPr>``
@@ -208,6 +206,17 @@ def clear_content(self):
208206 new_children .append (tcPr )
209207 self [:] = new_children
210208
209+ @property
210+ def grid_span (self ):
211+ """
212+ The integer number of columns this cell spans. Determined by
213+ ./w:tcPr/w:gridSpan/@val, it defaults to 1.
214+ """
215+ tcPr = self .tcPr
216+ if tcPr is None :
217+ return 1
218+ return tcPr .grid_span
219+
211220 @classmethod
212221 def new (cls ):
213222 """
@@ -220,6 +229,17 @@ def new(cls):
220229 '</w:tc>' % nsdecls ('w' )
221230 )
222231
232+ @property
233+ def vMerge (self ):
234+ """
235+ The value of the ./w:tcPr/w:vMerge/@val attribute, or |None| if the
236+ w:vMerge element is not present.
237+ """
238+ tcPr = self .tcPr
239+ if tcPr is None :
240+ return None
241+ return tcPr .vMerge_val
242+
223243 @property
224244 def width (self ):
225245 """
@@ -236,17 +256,55 @@ def width(self, value):
236256 tcPr = self .get_or_add_tcPr ()
237257 tcPr .width = value
238258
259+ def _insert_tcPr (self , tcPr ):
260+ """
261+ ``tcPr`` has a bunch of successors, but it comes first if it appears,
262+ so just overriding and using insert(0, ...) rather than spelling out
263+ successors.
264+ """
265+ self .insert (0 , tcPr )
266+ return tcPr
267+
268+ def _new_tbl (self ):
269+ return CT_Tbl .new ()
270+
239271
240272class CT_TcPr (BaseOxmlElement ):
241273 """
242274 ``<w:tcPr>`` element, defining table cell properties
243275 """
244- tcW = ZeroOrOne ('w:tcW' , successors = (
245- 'w:gridSpan' , 'w:hMerge' , 'w:vMerge' , 'w:tcBorders' , 'w:shd' ,
246- 'w:noWrap' , 'w:tcMar' , 'w:textDirection' , 'w:tcFitText' , 'w:vAlign' ,
247- 'w:hideMark' , 'w:headers' , 'w:cellIns' , 'w:cellDel' , 'w:cellMerge' ,
248- 'w:tcPrChange'
249- ))
276+ _tag_seq = (
277+ 'w:cnfStyle' , 'w:tcW' , 'w:gridSpan' , 'w:hMerge' , 'w:vMerge' ,
278+ 'w:tcBorders' , 'w:shd' , 'w:noWrap' , 'w:tcMar' , 'w:textDirection' ,
279+ 'w:tcFitText' , 'w:vAlign' , 'w:hideMark' , 'w:headers' , 'w:cellIns' ,
280+ 'w:cellDel' , 'w:cellMerge' , 'w:tcPrChange'
281+ )
282+ tcW = ZeroOrOne ('w:tcW' , successors = _tag_seq [2 :])
283+ gridSpan = ZeroOrOne ('w:gridSpan' , successors = _tag_seq [3 :])
284+ vMerge = ZeroOrOne ('w:vMerge' , successors = _tag_seq [5 :])
285+ del _tag_seq
286+
287+ @property
288+ def grid_span (self ):
289+ """
290+ The integer number of columns this cell spans. Determined by
291+ ./w:gridSpan/@val, it defaults to 1.
292+ """
293+ gridSpan = self .gridSpan
294+ if gridSpan is None :
295+ return 1
296+ return gridSpan .val
297+
298+ @property
299+ def vMerge_val (self ):
300+ """
301+ The value of the ./w:vMerge/@val attribute, or |None| if the
302+ w:vMerge element is not present.
303+ """
304+ vMerge = self .vMerge
305+ if vMerge is None :
306+ return None
307+ return vMerge .val
250308
251309 @property
252310 def width (self ):
@@ -263,3 +321,10 @@ def width(self):
263321 def width (self , value ):
264322 tcW = self .get_or_add_tcW ()
265323 tcW .width = value
324+
325+
326+ class CT_VMerge (BaseOxmlElement ):
327+ """
328+ ``<w:vMerge>`` element, specifying vertical merging behavior of a cell.
329+ """
330+ val = OptionalAttribute ('w:val' , ST_Merge , default = ST_Merge .CONTINUE )
0 commit comments