
    hL                       % S r SSKJr  SSKJrJrJrJr  SSKJ	r	  SSK
Jr  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJrJrJrJr  \(       a*  SSKJr  SSKJrJrJr  SSKJrJ r J!r!J"r"  SSKJ#r#  SSK$J%r%J&r&  Sr'S\(S'    " S S\5      r) " S S\5      r* " S S\5      r+ " S S\5      r, " S S\5      r- " S S\5      r.g)z-The |Table| object and related proxy classes.    )annotations)TYPE_CHECKINGIteratorcastoverload)	TypeAlias)BlockItemContainer)WD_STYLE_TYPE)WD_CELL_VERTICAL_ALIGNMENT)ST_Merge)CT_TblGridCol)InchesParented
StoryChildlazypropertyN)WD_ROW_HEIGHT_RULEWD_TABLE_ALIGNMENTWD_TABLE_DIRECTION)CT_RowCT_TblCT_TblPrCT_Tc)Length)ParagraphStyle_TableStylezTable | _Columns | _Rowsr   TableParentc                    ^  \ rS rSrSrSU 4S jjrSS jrS r\SS j5       r	\	R                  SS j5       r	\SS j5       r\R                  SS	 j5       rSS
 jrSS jr\S 5       rS S jr\S!S j5       r\S"S j5       r\R                  S#S j5       r\S 5       r\S$S j5       r\R                  S%S j5       r\S&S j5       r\S 5       r\S'S j5       rSrU =r$ )(Table   z7Proxy class for a WordprocessingML ``<w:tbl>`` element.c                D   > [         [        U ]  U5        Xl        Xl        g N)superr   __init___element_tblselftblparent	__class__s      </var/www/html/env/lib/python3.13/site-packages/docx/table.pyr#   Table.__init__    s    eT#F+	    c                    U R                   R                  nUR                  5       nXl        U R                   R                   H  nUR                  5       nXl        M     [        X05      $ )zIReturn a |_Column| object of `width`, newly added rightmost to the table.)r%   tblGridadd_gridColwtr_lstadd_tcwidth_Column)r'   r4   r/   gridColtrtcs         r+   
add_columnTable.add_column%   sU    ))##%%'	))""BBH # w%%r-   c                    U R                   nUR                  5       nUR                  R                   H3  nUR	                  5       nUR
                  c  M"  UR
                  Ul        M5     [        X 5      $ )z?Return a |_Row| instance, newly added bottom-most to the table.)r%   add_trr/   gridCol_lstr3   r1   r4   _Row)r'   r(   r7   r6   r8   s        r+   add_rowTable.add_row/   sV    iiZZ\{{..GByy$"99 / B~r-   c                .    U R                   R                  $ )zRead/write.

A member of :ref:`WdRowAlignment` or None, specifying the positioning of this
table between the page margins. |None| if no setting is specified, causing the
effective value to be inherited from the style hierarchy.
_tblPr	alignmentr'   s    r+   rD   Table.alignment9   s     {{$$$r-   c                $    XR                   l        g r!   rB   r'   values     r+   rD   rF   C   s     %r-   c                .    U R                   R                  $ )z|True| if column widths can be automatically adjusted to improve the fit of
cell contents.

|False| if table layout is fixed. Column widths are adjusted in either case if
total column width exceeds page width. Read/write boolean.
rC   autofitrE   s    r+   rL   Table.autofitG   s     {{"""r-   c                $    XR                   l        g r!   rK   rH   s     r+   rL   rM   Q   s    #r-   c                B    X!U R                   -  -   nU R                  U   $ )zR|_Cell| at `row_idx`, `col_idx` intersection.

(0, 0) is the top, left-most cell.
_column_count_cells)r'   row_idxcol_idxcell_idxs       r+   cell
Table.cellU   s&    
 (:(::;{{8$$r-   c                    U R                   n[        U[        U5      U R                  5      nU Vs/ s H  oBU   PM	     sn$ s  snf )z>Sequence of cells in the column at `column_idx` in this table.)rR   rangelenrQ   )r'   
column_idxcellsidxsidxs        r+   column_cellsTable.column_cells]   s=    ZUT-?-?@&*+dsc
d+++s   Ac                .    [        U R                  U 5      $ )zG|_Columns| instance representing the sequence of columns in this table.)_Columnsr%   rE   s    r+   columnsTable.columnsc   s     		4((r-   c                F    U R                   nX-  nX2-   nU R                  X4 $ )zoDEPRECATED: Use `table.rows[row_idx].cells` instead.

Sequence of cells in the row at `row_idx` in this table.
rP   )r'   rS   column_countstartends        r+   	row_cellsTable.row_cellsh   s.    
 ))&"{{5%%r-   c                .    [        U R                  U 5      $ )z?|_Rows| instance containing the sequence of rows in this table.)_Rowsr%   rE   s    r+   rows
Table.rowsr   s     TYY%%r-   c                    U R                   R                  n[        SU R                  R	                  U[
        R                  5      5      $ )a-  |_TableStyle| object representing the style applied to this table.

Read/write. The default table style for the document (often `Normal Table`) is
returned if the table has no directly-applied style. Assigning |None| to this
property removes any directly-applied table style causing it to inherit the
default table style of the document.

Note that the style name of a table style differs slightly from that displayed
in the user interface; a hyphen, if it appears, must be removed. For example,
`Light Shading - Accent 1` becomes `Light Shading Accent 1`.
_TableStyle | None)r%   tblStyle_valr   part	get_styler
   TABLE)r'   style_ids     r+   styleTable.stylew   s8     99))($))*=*=hH[H[*\]]r-   c                x    U R                   R                  U[        R                  5      nX R                  l        g r!   )rr   get_style_idr
   rt   r%   rq   )r'   style_or_nameru   s      r+   rv   rw      s(    99))-9L9LM!)		r-   c                    U $ )zProvide child objects with reference to the |Table| object they belong to,
without them having to know their direct parent is a |Table| object.

This is the terminus of a series of `parent._table` calls from an arbitrary
child through its ancestors.
 rE   s    r+   tableTable.table   s	     r-   c                B    [        SU R                  R                  5      $ )zMember of :ref:`WdTableDirection` indicating cell-ordering direction.

For example: `WD_TABLE_DIRECTION.LTR`. |None| indicates the value is inherited
from the style hierarchy.
WD_TABLE_DIRECTION | None)r   r%   bidiVisual_valrE   s    r+   table_directionTable.table_direction   s     /1I1IJJr-   c                $    XR                   l        g r!   )r$   r   rH   s     r+   r   r      s    ',$r-   c                p   U R                   n/ nU R                  R                  5        H  n[        UR                  5       Hm  nUR
                  [        R                  :X  a  UR                  X!*    5        M7  US:  a  UR                  US   5        MS  UR                  [        X05      5        Mo     M     U$ )zA sequence of |_Cell| objects, one for each cell of the layout grid.

If the table contains a span, one or more |_Cell| object references are
repeated.
r   )
rQ   r%   iter_tcsrY   	grid_spanvMerger   CONTINUEappend_Cell)r'   	col_countr\   r8   grid_span_idxs        r+   rR   Table._cells   s     &&	))$$&B!&r||!499 1 11LLz!23"Q&LLr+LLr1 "5 ' r-   c                .    U R                   R                  $ )z)The number of grid columns in this table.)r%   r   rE   s    r+   rQ   Table._column_count   s     yy"""r-   c                .    U R                   R                  $ r!   )r%   tblPrrE   s    r+   rC   Table._tblPr   s    yyr-   )r$   r%   )r(   r   r)   t.ProvidesStoryPart)r4   r   )returnWD_TABLE_ALIGNMENT | None)rI   r   )r   bool)rI   r   )rS   intrT   r   r   r   )r[   r   r   list[_Cell])rS   r   r   r   )r   rl   )r   rp   )rz   z_TableStyle | str | None)r   r   )rI   r   )r   r   )r   r   )__name__
__module____qualname____firstlineno____doc__r#   r9   r?   propertyrD   setterrL   rV   r_   r   rc   ri   rm   rv   r}   r   rR   rQ   rC   __static_attributes____classcell__r*   s   @r+   r   r      sT   A
& % % & & # # ^^$ $%, ) )& & & ^ ^ \\* *   K K - -  $ # #  r-   r   c                  V  ^  \ rS rSrSrSU 4S jjrSSU 4S jjjr      SU 4S jjr\SS j5       r	SS jr
\U 4S j5       r\U 4S	 j5       r\SS
 j5       r\R                  SS j5       r\S 5       r\R                  SS j5       r\S 5       r\R                  SS j5       rSrU =r$ )r      zTable cell.c                j   > [         [        U ]  U[        SU5      5        X l        U=U l        U l        g )Nr   )r"   r   r#   r   _parent_tcr$   )r'   r8   r)   r*   s      r+   r#   _Cell.__init__   s/    eT#B-BF(KL#%%4=r-   c                *   > [         [        U ]  X5      $ )aS  Return a paragraph newly added to the end of the content in this cell.

If present, `text` is added to the paragraph in a single run. If specified, the
paragraph style `style` is applied. If `style` is not specified or is |None|,
the result is as though the 'Normal' style was applied. Note that the formatting
of text in a cell can be influenced by the table style. `text` can contain tab
(``\t``) characters, which are converted to the appropriate XML form for a tab.
`text` can also include newline (``\n``) or carriage return (``\r``)
characters, each of which is converted to a line break.
)r"   r   add_paragraph)r'   textrv   r*   s      r+   r   _Cell.add_paragraph   s     UD/<<r-   c                   > U R                   b  U R                   O
[        S5      n[        [        U ]  XU5      nU R                  5         U$ )zReturn a table newly added to this cell after any existing cell content.

The new table will have `rows` rows and `cols` columns.

An empty paragraph is added after the table because Word requires a paragraph
element as the last element in every cell.
   )r4   r   r"   r   	add_tabler   )r'   rm   colsr4   r}   r*   s        r+   r   _Cell.add_table   sA     #jj4

&)eT,T?r-   c                .    U R                   R                  $ )zNumber of layout-grid cells this cell spans horizontally.

A "normal" cell has a grid-span of 1. A horizontally merged cell has a grid-span of 2 or
more.
)r   r   rE   s    r+   r   _Cell.grid_span   s     xx!!!r-   c                |    U R                   UR                   p2UR                  U5      n[        X@R                  5      $ )zReturn a merged cell created by spanning the rectangular region having this
cell and `other_cell` as diagonal corners.

Raises |InvalidSpanError| if the cells do not define a rectangular region.
)r   merger   r   )r'   
other_cellr8   tc_2	merged_tcs        r+   r   _Cell.merge   s/     88Z^^DHHTN	Y--r-   c                    > [         [        U ]
  $ )zList of paragraphs in the cell.

A table cell is required to contain at least one block-level element and end
with a paragraph. By default, a new cell contains a single paragraph. Read-only
)r"   r   
paragraphsr'   r*   s    r+   r   _Cell.paragraphs   s     UD,,r-   c                    > [         [        U ]
  $ )zBList of tables in the cell, in the order they appear.

Read-only.
)r"   r   tablesr   s    r+   r   _Cell.tables   s     UD((r-   c                F    SR                  S U R                   5       5      $ )zThe entire contents of this cell as a string of text.

Assigning a string to this property replaces all existing content with a single
paragraph containing the assigned text in a single run.

c              3  8   #    U  H  oR                   v   M     g 7fr!   )r   ).0ps     r+   	<genexpr>_Cell.text.<locals>.<genexpr>  s     9As   )joinr   rE   s    r+   r   
_Cell.text  s     yy9999r-   c                    U R                   nUR                  5         UR                  5       nUR                  5       nXl        g)zoWrite-only.

Set entire contents of cell to the string `text`. Any existing content or
revisions are replaced.
N)r   clear_contentadd_padd_rr   )r'   r   r8   r   rs        r+   r   r     s4     XX
HHJGGIr-   c                N    U R                   R                  nUc  gUR                  $ )zMember of :ref:`WdCellVerticalAlignment` or None.

A value of |None| indicates vertical alignment for this cell is inherited.
Assigning |None| causes any explicitly defined vertical alignment to be removed,
restoring inheritance.
N)r$   tcPr
vAlign_val)r'   r   s     r+   vertical_alignment_Cell.vertical_alignment  s%     }}!!<r-   c                D    U R                   R                  5       nXl        g r!   )r$   get_or_add_tcPrr   )r'   rI   r   s      r+   r   r   +  s    }},,.r-   c                .    U R                   R                  $ )zEThe width of this cell in EMU, or |None| if no explicit width is set.r   r4   rE   s    r+   r4   _Cell.width0  s     xx~~r-   c                $    XR                   l        g r!   r   rH   s     r+   r4   r   5  s    r-   )r$   r   r   )r8   r   r)   r   ) N)r   strrv   zstr | ParagraphStyle | None)rm   r   r   r   r   r   r   r   )r   r   )r   r   )r   r   )rI   z!WD_CELL_VERTICAL_ALIGNMENT | None)rI   r   )r   r   r   r   r   r#   r   r   r   r   r   r   r   r   r   r   r4   r   r   r   s   @r+   r   r      s    &
= ="	 " ". - - ) ) : : 
[[
 
 
 
       \\ r-   r   c                     ^  \ rS rSrSrS
U 4S jjr\SS j5       r\SS j5       r\SS j5       r	\	R                  SS j5       r	\S 5       rS	rU =r$ )r5   i:  zTable column.c                D   > [         [        U ]  U5        X l        Xl        g r!   )r"   r5   r#   r   _gridCol)r'   r6   r)   r*   s      r+   r#   _Column.__init__=  s    gt%f-r-   c                ^    [        U R                  R                  U R                  5      5      $ )zDSequence of |_Cell| instances corresponding to cells in this column.)tupler}   r_   _indexrE   s    r+   r\   _Column.cellsB  s"     TZZ,,T[[9::r-   c                .    U R                   R                  $ )z7Reference to the |Table| object this column belongs to.r   r}   rE   s    r+   r}   _Column.tableG       ||!!!r-   c                .    U R                   R                  $ )zGThe width of this column in EMU, or |None| if no explicit width is set.r   r1   rE   s    r+   r4   _Column.widthL  s     }}r-   c                $    XR                   l        g r!   r   rH   s     r+   r4   r   Q  s    r-   c                .    U R                   R                  $ )z6Index of this column in its table, starting from zero.)r   gridCol_idxrE   s    r+   r   _Column._indexU  s     }}(((r-   )r   r   )r6   r   r)   r   r   ztuple[_Cell, ...]r   r   r   Length | NonerI   r   )r   r   r   r   r   r#   r   r\   r}   r4   r   r   r   r   r   s   @r+   r5   r5   :  ss     
 ; ; " "   \\    ) )r-   r5   c                  j   ^  \ rS rSrSrS
U 4S jjrSS jrS rS r\	SS j5       r
\	S 5       rS	rU =r$ )rb   i[  z|Sequence of |_Column| instances corresponding to the columns in a table.

Supports ``len()``, iteration and indexed access.
c                D   > [         [        U ]  U5        X l        Xl        g r!   )r"   rb   r#   r   r%   r&   s      r+   r#   _Columns.__init__a  s    h&v.	r-   c                t     U R                   U   n[        X 5      $ ! [         a    SU-  n[        U5      ef = f)z*Provide indexed access, e.g. 'columns[0]'.z!column index [%d] is out of range)_gridCol_lst
IndexErrorr5   )r'   r^   r6   msgs       r+   __getitem___Columns.__getitem__f  sI    	"'',G w%%  	"5;CS/!	"s    7c              #  L   #    U R                    H  n[        X5      v   M     g 7fr!   )r   r5   )r'   r6   s     r+   __iter___Columns.__iter__o  s      ((G'(( )s   "$c                ,    [        U R                  5      $ r!   )rZ   r   rE   s    r+   __len___Columns.__len__s  s    4$$%%r-   c                .    U R                   R                  $ )zBReference to the |Table| object this column collection belongs to.r   rE   s    r+   r}   _Columns.tablev  r   r-   c                F    U R                   R                  nUR                  $ )z^Sequence containing ``<w:gridCol>`` elements for this table, each
representing a table column.)r%   r/   r=   )r'   r/   s     r+   r   _Columns._gridCol_lst{  s     ))##"""r-   r   r%   r(   r   r)   r   )r^   r   r   )r   r   r   r   r   r#   r   r  r  r   r}   r   r   r   r   s   @r+   rb   rb   [  sD    

&)& " " # #r-   rb   c                    ^  \ rS rSrSrSU 4S jjr\SS j5       r\SS j5       r\SS j5       r	\SS j5       r
\
R                  SS j5       r
\SS	 j5       r\R                  SS
 j5       r\SS j5       r\SS j5       rSrU =r$ )r>   i  z
Table row.c                T   > [         [        U ]  U5        X l        U=U l        U l        g r!   )r"   r>   r#   r   _trr$   )r'   r7   r)   r*   s      r+   r#   _Row.__init__  s%    dD"6*#%%4=r-   c                J   ^ ^ SUU 4S jjmSUU 4S jjn[        U" 5       5      $ )aB  Sequence of |_Cell| instances corresponding to cells in this row.

Note that Word allows table rows to start later than the first column and end before the
last column.

- Only cells actually present are included in the return value.
- This implies the length of this cell sequence may differ between rows of the same table.
- If you are reading the cells from each row to form a rectangular "matrix" data structure
  of the table cell values, you will need to account for empty leading and/or trailing
  layout-grid positions using `.grid_cols_before` and `.grid_cols_after`.

c              3     >#    U R                   S:X  a  T" U R                  5       Sh  vN   g[        U TR                  5      n[	        U R
                  5       H  nUv   M	     g N<7f)a.  Generate a cell object for each layout-grid cell in `tc`.

In particular, a `<w:tc>` element with a horizontal "span" with generate the same cell
multiple times, one for each grid-cell being spanned. This approximates a row in a
"uniform" table, where each row has a cell for each column in the table.
continueN)r   	_tc_abover   r}   rY   r   )r8   rV   _iter_tc_cellsr'   s      r+   r  !_Row.cells.<locals>.iter_tc_cells  sX      yyJ&(666 TZZ(D2<<(
 ) 7s   &A(A&=A(c               3  l   >#    TR                   R                   H  n T" U 5       Sh  vN   M     g N	7f)zJGenerate `_Cell` instance for each populated layout-grid cell in this row.N)r  tc_lst)r8   r  r'   s    r+   _iter_row_cells#_Row.cells.<locals>._iter_row_cells  s)     hhoo(,,, &,s   %42
4)r8   r   r   Iterator[_Cell])r   r  )r   )r'   r  r  s   ` @r+   r\   
_Row.cells  s'    	 	.	- 	-
 _&''r-   c                .    U R                   R                  $ )a^  Count of unpopulated grid-columns after the last cell in this row.

Word allows a row to "end early", meaning that one or more cells are not present at the
end of that row.

Note these are not simply "empty" cells. The renderer reads this value and "skips" this
many columns after drawing the last cell.

Note this also implies that not all rows are guaranteed to have the same number of cells,
e.g. `_Row.cells` could have length `n` for one row and `n - m` for the next row in the same
table. Visually this appears as a column (at the beginning or end, not in the middle) with
one or more cells missing.
)r  
grid_afterrE   s    r+   grid_cols_after_Row.grid_cols_after  s     xx"""r-   c                .    U R                   R                  $ )aV  Count of unpopulated grid-columns before the first cell in this row.

Word allows a row to "start late", meaning that one or more cells are not present at the
beginning of that row.

Note these are not simply "empty" cells. The renderer reads this value and skips forward to
the table layout-grid position of the first cell in this row; the renderer "skips" this many
columns before drawing the first cell.

Note this also implies that not all rows are guaranteed to have the same number of cells,
e.g. `_Row.cells` could have length `n` for one row and `n - m` for the next row in the same
table.
)r  grid_beforerE   s    r+   grid_cols_before_Row.grid_cols_before  s     xx###r-   c                .    U R                   R                  $ )zfReturn a |Length| object representing the height of this cell, or |None| if
no explicit height is set.r  trHeight_valrE   s    r+   height_Row.height  s     xx$$$r-   c                $    XR                   l        g r!   r&  rH   s     r+   r(  r)    s     %r-   c                .    U R                   R                  $ )zReturn the height rule of this cell as a member of the :ref:`WdRowHeightRule`.

This value is |None| if no explicit height_rule is set.
r  trHeight_hRulerE   s    r+   height_rule_Row.height_rule  s     xx&&&r-   c                $    XR                   l        g r!   r,  rH   s     r+   r.  r/    s    "'r-   c                .    U R                   R                  $ )z4Reference to the |Table| object this row belongs to.r   rE   s    r+   r}   
_Row.table  r   r-   c                .    U R                   R                  $ )z3Index of this row in its table, starting from zero.)r  tr_idxrE   s    r+   r   _Row._index  s     xxr-   )r$   r   r  )r7   r   r)   r   r   r   r   r   )r   WD_ROW_HEIGHT_RULE | None)rI   r6  r   )r   r   r   r   r   r#   r   r\   r  r#  r(  r   r.  r}   r   r   r   r   s   @r+   r>   r>     s    &
 *( *(X # #  $ $  % %
 ]]& & ' ' ( ( " "  r-   r>   c                     ^  \ rS rSrSrSU 4S jjr\SS j5       r\SS j5       rSS jrS rS r	\
SS	 j5       rS
rU =r$ )rl   i  z~Sequence of |_Row| objects corresponding to the rows in a table.

Supports ``len()``, iteration, indexed access, and slicing.
c                D   > [         [        U ]  U5        X l        Xl        g r!   )r"   rl   r#   r   r%   r&   s      r+   r#   _Rows.__init__  s    eT#F+	r-   c                    g r!   r|   r'   r^   s     r+   r   _Rows.__getitem__  s    -0r-   c                    g r!   r|   r;  s     r+   r   r<  	  s    58r-   c                    [        U 5      U   $ )z7Provide indexed access, (e.g. `rows[0]` or `rows[1:3]`))listr;  s     r+   r   r<    s    Dz#r-   c                D   ^  U 4S jT R                   R                   5       $ )Nc              3  <   >#    U  H  n[        UT5      v   M     g 7fr!   )r>   )r   r7   r'   s     r+   r   !_Rows.__iter__.<locals>.<genexpr>  s     :)92R)9s   )r%   r2   rE   s   `r+   r  _Rows.__iter__  s    :)9)9::r-   c                @    [        U R                  R                  5      $ r!   )rZ   r%   r2   rE   s    r+   r  _Rows.__len__  s    499##$$r-   c                .    U R                   R                  $ )z?Reference to the |Table| object this row collection belongs to.r   rE   s    r+   r}   _Rows.table  r   r-   r
  r  )r^   r   r   r>   )r^   slicer   z
list[_Row])r^   zint | slicer   z_Row | list[_Row]r   )r   r   r   r   r   r#   r   r   r  r  r   r}   r   r   r   s   @r+   rl   rl     sN    

 0 08 8;% " "r-   rl   )/r   
__future__r   typingr   r   r   r   typing_extensionsr   docx.blkcntnrr	   docx.enum.styler
   docx.enum.tabler   docx.oxml.simpletypesr   docx.oxml.tabler   docx.sharedr   r   r   r   
docx.typestypestr   r   r   r   r   r   r   r   docx.styles.styler   r   r   __annotations__r   r   r5   rb   r>   rl   r|   r-   r+   <module>rW     s    3 " : : ' , ) 6 * ) B BZZ??"
 4Y 3`J `Fw wt)h )B%#x %#Pu8 up"H "r-   