
    j7                    V   d Z ddlmZ ddlmZmZmZmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZmZmZ er"ddlmZ dd	lmZmZ dd
lmZmZ ddlmZ ddlmZ  G d de          Z G d de	          Z G d de          Z  G d de          Z! G d de          Z" G d de          Z#dS )z-The |Table| object and related proxy classes.    )annotations)TYPE_CHECKINGListTupleoverload)BlockItemContainer)WD_STYLE_TYPE)ST_Merge)InchesParentedlazyproperty)types)WD_TABLE_ALIGNMENTWD_TABLE_DIRECTION)CT_TblCT_TblPr)Length)_TableStylec                      e Zd ZdZd+ fdZd,d	Zd
 Zed-d            Zej	        d.d            Zed/d            Z
e
j	        d0d            Z
d1dZd2dZed             Zd3dZed4d            Zed5d             Zej	        d6d"            Zed#             Zed7d%            Zej	        d8d&            Zed9d'            Zed(             Zed:d*            Z xZS );Tablez7Proxy class for a WordprocessingML ``<w:tbl>`` element.tblr   parentt.StoryChildc                t    t          t          |                               |           |x| _        | _        d S N)superr   __init___element_tblselfr   r   	__class__s      T/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/docx/table.pyr   zTable.__init__   s3    eT##F+++$''			    widthr   c                    | j         j        }|                                }||_        | j         j        D ]}|                                }||_        t          ||           S )zIReturn a |_Column| object of `width`, newly added rightmost to the table.)r   tblGridadd_gridColwtr_lstadd_tcr%   _Column)r!   r%   r'   gridColtrtcs         r#   
add_columnzTable.add_column   s^    )#%%''	)" 	 	BBBHHw%%%r$   c                    | j         }|                                }|j        j        D ]"}|                                }|j        |_        #t          ||           S )z?Return a |_Row| instance, newly added bottom-most to the table.)r   add_trr'   gridCol_lstr+   r)   r%   _Row)r!   r   r.   r-   r/   s        r#   add_rowzTable.add_row%   sP    iZZ\\{. 	! 	!GByBHHB~~r$   returnWD_TABLE_ALIGNMENT | Nonec                    | j         j        S )a  Read/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#   r;   zTable.alignment.   s     {$$r$   valuec                    || j         _        d S r   r9   r!   r=   s     r#   r;   zTable.alignment8   s     %r$   boolc                    | j         j        S )a  |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.
        r:   autofitr<   s    r#   rC   zTable.autofit<   s     {""r$   c                    || j         _        d S r   rB   r?   s     r#   rC   zTable.autofitF   s    #r$   row_idxintcol_idx_Cellc                6    ||| j         z  z   }| j        |         S )zb|_Cell| at `row_idx`, `col_idx` intersection.

        (0, 0) is the top, left-most cell.
        _column_count_cells)r!   rE   rG   cell_idxs       r#   cellz
Table.cellJ   s#    
 g(::;{8$$r$   
column_idxList[_Cell]c                t    | j         t          |t                    | j                  }fd|D             S )z>Sequence of cells in the column at `column_idx` in this table.c                     g | ]
}|         S  rS   ).0idxcellss     r#   
<listcomp>z&Table.column_cells.<locals>.<listcomp>V   s    +++sc
+++r$   )rL   rangelenrK   )r!   rO   idxsrV   s      @r#   column_cellszTable.column_cellsR   s>    ZUT-?@@++++d++++r$   c                ,    t          | j        |           S )zG|_Columns| instance representing the sequence of columns in this table.)_Columnsr   r<   s    r#   columnszTable.columnsX   s     	4(((r$   c                B    | j         }||z  }||z   }| j        ||         S )z8Sequence of cells in the row at `row_idx` in this table.rJ   )r!   rE   column_countstartends        r#   	row_cellszTable.row_cells]   s/    ),&l"{59%%r$   _Rowsc                ,    t          | j        |           S )z?|_Rows| instance containing the sequence of rows in this table.)rd   r   r<   s    r#   rowsz
Table.rowsd   s     TY%%%r$   _TableStyle | Nonec                d    | j         j        }| j                            |t          j                  S )am  |_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`.
        )r   tblStyle_valpart	get_styler	   TABLE)r!   style_ids     r#   stylezTable.stylei   s)     9)y""8]-@AAAr$   style_or_namec                h    | j                             |t          j                  }|| j        _        d S r   )rj   get_style_idr	   rl   r   ri   )r!   ro   rm   s      r#   rn   zTable.styley   s,    9))-9LMM!)	r$   c                    | S )a  Provide 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.
        rS   r<   s    r#   tablezTable.table~   s	     r$   WD_TABLE_DIRECTION | Nonec                    | j         j        S )zMember of :ref:`WdTableDirection` indicating cell-ordering direction.

        For example: `WD_TABLE_DIRECTION.LTR`. |None| indicates the value is inherited
        from the style hierarchy.
        r   bidiVisual_valr<   s    r#   table_directionzTable.table_direction   s     }++r$   c                    || j         _        d S r   rv   r?   s     r#   rx   zTable.table_direction   s    ',$$$r$   c                l   | j         }g }| j                                        D ]}t          |j                  D ]y}|j        t          j        k    r|                    ||                     4|dk    r|                    |d                    V|                    t          ||                      z|S )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   )
rK   r   iter_tcsrX   	grid_spanvMerger
   CONTINUEappendrH   )r!   	col_countrV   r/   grid_span_idxs        r#   rL   zTable._cells   s     &	)$$&& 	2 	2B!&r|!4!4 2 29 111LL	z!23333"Q&&LLr++++LLr411112 r$   c                    | j         j        S )z)The number of grid columns in this table.)r   r   r<   s    r#   rK   zTable._column_count   s     y""r$   r   c                    | j         j        S r   )r   tblPrr<   s    r#   r:   zTable._tblPr   s    yr$   )r   r   r   r   )r%   r   )r6   r7   )r=   r7   )r6   r@   )r=   r@   )rE   rF   rG   rF   r6   rH   )rO   rF   r6   rP   )rE   rF   r6   rP   )r6   rd   )r6   rg   )ro   rg   )r6   rt   )r=   rt   )r6   rP   )r6   r   )__name__
__module____qualname____doc__r   r0   r5   propertyr;   setterrC   rN   r[   r   r^   rc   rf   rn   rs   rx   rL   rK   r:   __classcell__r"   s   @r#   r   r      sc       AA( ( ( ( ( (& & & &   % % % X% & & & & # # # X# ^$ $ $ ^$% % % %, , , , ) ) \)& & & & & & & \& B B B XB \* * * \*   X , , , X, - - - -    X$ # # X#    X    r$   r   c                      e Zd ZdZ fdZd fd	Z fdZd Ze fd            Z	e fd	            Z
edd            Zej        d             Zed             Zej        d             Zed             Zej        d             Z xZS )rH   zTable cell.c                v    t          t          |                               ||           |x| _        | _        d S r   )r   rH   r   _tcr   )r!   r/   r   r"   s      r#   r   z_Cell.__init__   s5    eT##B///#%%4===r$    Nc                V    t          t          |                               ||          S )a  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   rH   add_paragraph)r!   textrn   r"   s      r#   r   z_Cell.add_paragraph   s%     UD!!//e<<<r$   c                    | j         | j         nt          d          }t          t          |                               |||          }|                                  |S )a
  Return a table newly added to this cell after any existing cell content,
        having `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.
        N   )r%   r   r   rH   	add_tabler   )r!   rf   colsr%   rs   r"   s        r#   r   z_Cell.add_table   sU     #j4

&))eT"",,T4??r$   c                r    | j         |j         }}|                    |          }t          || j                  S )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   mergerH   _parent)r!   
other_cellr/   tc_2	merged_tcs        r#   r   z_Cell.merge   s2     8Z^DHHTNN	Y---r$   c                8    t          t          |           j        S )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   rH   
paragraphsr!   r"   s    r#   r   z_Cell.paragraphs   s     UD!!,,r$   c                8    t          t          |           j        S )zRList of tables in the cell, in the order they appear.

        Read-only.
        )r   rH   tablesr   s    r#   r   z_Cell.tables   s     UD!!((r$   r6   strc                J    d                     d | j        D                       S )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  $   K   | ]}|j         V  d S r   )r   )rT   ps     r#   	<genexpr>z_Cell.text.<locals>.<genexpr>   s$      99A999999r$   )joinr   r<   s    r#   r   z
_Cell.text   s'     yy99999999r$   c                    | j         }|                                 |                                }|                                }||_        dS )zWrite-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   r/   r   rs        r#   r   z
_Cell.text   sB     X
HHJJGGIIr$   c                0    | j         j        }|dS |j        S )a  Member 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_alignmentz_Cell.vertical_alignment  s      }!<4r$   c                F    | j                                         }||_        d S r   )r   get_or_add_tcPrr   )r!   r=   r   s      r#   r   z_Cell.vertical_alignment  s     },,..r$   c                    | j         j        S )zEThe width of this cell in EMU, or |None| if no explicit width is set.r   r%   r<   s    r#   r%   z_Cell.width  s     x~r$   c                    || j         _        d S r   r   r?   s     r#   r%   z_Cell.width  s    r$   )r   N)r6   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r%   r   r   s   @r#   rH   rH      s}       & & & & &= = = = = =
 
 
 
 
. . . - - - - X- ) ) ) ) X) : : : X: 
[
 
 [
 
 
 X
         X \  \    r$   rH   c                       e Zd ZdZ fdZed             Zed             Zed             Zej	        d             Zed             Z
 xZS )r,   zTable column.c                f    t          t          |                               |           || _        d S r   )r   r,   r   _gridCol)r!   r-   r   r"   s      r#   r   z_Column.__init__"  s,    gt%%f---r$   c                Z    t          | j                            | j                            S )zDSequence of |_Cell| instances corresponding to cells in this column.)tuplers   r[   _indexr<   s    r#   rV   z_Column.cells&  s$     TZ,,T[99:::r$   c                    | j         j        S )z7Reference to the |Table| object this column belongs to.r   rs   r<   s    r#   rs   z_Column.table+       |!!r$   c                    | j         j        S )zGThe width of this column in EMU, or |None| if no explicit width is set.r   r)   r<   s    r#   r%   z_Column.width0  s     }r$   c                    || j         _        d S r   r   r?   s     r#   r%   z_Column.width5  s    r$   c                    | j         j        S )z6Index of this column in its table, starting from zero.)r   gridCol_idxr<   s    r#   r   z_Column._index9  s     }((r$   )r   r   r   r   r   r   rV   rs   r%   r   r   r   r   s   @r#   r,   r,     s                  ; ; X; " " X"   X \    \  ) ) X) ) ) ) )r$   r,   c                  `     e Zd ZdZ fdZd Zd Zd Zed             Z	ed             Z
 xZS )r]   zSequence of |_Column| instances corresponding to the columns in a table.

    Supports ``len()``, iteration and indexed access.
    c                f    t          t          |                               |           || _        d S r   )r   r]   r   r   r    s      r#   r   z_Columns.__init__E  s,    h&&v...			r$   c                    	 | j         |         }n"# t          $ r d|z  }t          |          w xY wt          ||           S )z*Provide indexed access, e.g. 'columns[0]'.z!column index [%d] is out of range)_gridCol_lst
IndexErrorr,   )r!   rU   r-   msgs       r#   __getitem__z_Columns.__getitem__I  sY    	"',GG 	" 	" 	"5;CS//!	" w%%%s    /c              #  B   K   | j         D ]}t          ||           V  d S r   )r   r,   )r!   r-   s     r#   __iter__z_Columns.__iter__R  s;      ( 	) 	)G'4((((((	) 	)r$   c                *    t          | j                  S r   )rY   r   r<   s    r#   __len__z_Columns.__len__V  s    4$%%%r$   c                    | j         j        S )zBReference to the |Table| object this column collection belongs to.r   r<   s    r#   rs   z_Columns.tableY  r   r$   c                (    | j         j        }|j        S )zfSequence containing ``<w:gridCol>`` elements for this table, each
        representing a table column.)r   r'   r3   )r!   r'   s     r#   r   z_Columns._gridCol_lst^  s     )#""r$   )r   r   r   r   r   r   r   r   r   rs   r   r   r   s   @r#   r]   r]   ?  s         
    & & &) ) )& & & " " X" # # X# # # # #r$   r]   c                       e Zd ZdZ fdZedd            Zed             Zej        d             Zed             Z	e	j        d	             Z	ed
             Z
ed             Z xZS )r4   z
Table row.c                t    t          t          |                               |           |x| _        | _        d S r   )r   r4   r   _trr   )r!   r.   r   r"   s      r#   r   z_Row.__init__i  s3    dD""6***#%%4===r$   r6   Tuple[_Cell]c                Z    t          | j                            | j                            S )zASequence of |_Cell| instances corresponding to cells in this row.)r   rs   rc   r   r<   s    r#   rV   z
_Row.cellsm  s$     TZ))$+66777r$   c                    | j         j        S )znReturn a |Length| object representing the height of this cell, or |None| if
        no explicit height is set.r   trHeight_valr<   s    r#   heightz_Row.heightr  s     x$$r$   c                    || j         _        d S r   r   r?   s     r#   r   z_Row.heightx  s     %r$   c                    | j         j        S )zReturn the height rule of this cell as a member of the :ref:`WdRowHeightRule`
        enumeration, or |None| if no explicit height_rule is set.r   trHeight_hRuler<   s    r#   height_rulez_Row.height_rule|  s     x&&r$   c                    || j         _        d S r   r   r?   s     r#   r   z_Row.height_rule  s    "'r$   c                    | j         j        S )z4Reference to the |Table| object this row belongs to.r   r<   s    r#   rs   z
_Row.table  r   r$   c                    | j         j        S )z3Index of this row in its table, starting from zero.)r   tr_idxr<   s    r#   r   z_Row._index  s     xr$   )r6   r   )r   r   r   r   r   r   rV   r   r   r   rs   r   r   r   s   @r#   r4   r4   f  s       & & & & & 8 8 8 X8 % % X%
 ]& & ]& ' ' X'
 ( ( ( " " X"   X    r$   r4   c                  |     e Zd ZdZ fdZedd            Zedd
            ZddZd Zd Ze	d             Z
 xZS )rd   zSequence of |_Row| objects corresponding to the rows in a table.

    Supports ``len()``, iteration, indexed access, and slicing.
    c                f    t          t          |                               |           || _        d S r   )r   rd   r   r   r    s      r#   r   z_Rows.__init__  s,    eT##F+++			r$   rU   rF   r6   r4   c                    d S r   rS   r!   rU   s     r#   r   z_Rows.__getitem__      r$   slice
List[_Row]c                    d S r   rS   r   s     r#   r   z_Rows.__getitem__  r   r$   int | slice_Row | List[_Row]c                ,    t          |           |         S )z7Provide indexed access, (e.g. `rows[0]` or `rows[1:3]`))listr   s     r#   r   z_Rows.__getitem__  s    Dzz#r$   c                4      fd j         j        D             S )Nc              3  8   K   | ]}t          |          V  d S r   )r4   )rT   r.   r!   s     r#   r   z!_Rows.__iter__.<locals>.<genexpr>  s+      ::2R::::::r$   )r   r*   r<   s   `r#   r   z_Rows.__iter__  s"    ::::)9::::r$   c                4    t          | j        j                  S r   )rY   r   r*   r<   s    r#   r   z_Rows.__len__  s    49#$$$r$   c                    | j         j        S )z?Reference to the |Table| object this row collection belongs to.r   r<   s    r#   rs   z_Rows.table  r   r$   )rU   rF   r6   r4   )rU   r   r6   r   )rU   r   r6   r   )r   r   r   r   r   r   r   r   r   r   rs   r   r   s   @r#   rd   rd     s         
        X    X   ; ; ;% % % " " X" " " " "r$   rd   N)$r   
__future__r   typingr   r   r   r   docx.blkcntnrr   docx.enum.styler	   docx.oxml.simpletypesr
   docx.sharedr   r   r   docxr   tdocx.enum.tabler   r   docx.oxml.tabler   r   r   docx.styles.styler   r   rH   r,   r]   r4   rd   rS   r$   r#   <module>r     s   3 3 " " " " " " 7 7 7 7 7 7 7 7 7 7 7 7 , , , , , , ) ) ) ) ) ) * * * * * * 6 6 6 6 6 6 6 6 6 6 .FFFFFFFF00000000""""""------[ [ [ [ [H [ [ [|j j j j j j j jZ) ) ) ) )h ) ) )@$# $# $# $# $#x $# $# $#N( ( ( ( (8 ( ( (V" " " " "H " " " " "r$   