
    ,hL                    x   U 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 ddlmZ dd	lmZ dd
lmZmZmZmZ er*ddlmZ ddlmZmZmZ ddlmZm Z m!Z!m"Z" ddlm#Z# ddl$m%Z%m&Z& dZ'de(d<    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.y)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                      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                  dd       Z
dd	Zdd
Zed        ZddZedd       Zed d       Zej                  d!d       Zed        Zed"d       Zej                  d#d       Zed$d       Zed        Zed%d       Z xZS )&Tablez7Proxy class for a WordprocessingML ``<w:tbl>`` element.c                H    t         t        |   |       || _        || _        y N)superr   __init___element_tblselftblparent	__class__s      L/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/docx/table.pyr"   zTable.__init__    s     eT#F+	    c                    | j                   j                  }|j                         }||_        | j                   j                  D ]  }|j                         }||_         t        ||       S )zIReturn a |_Column| object of `width`, newly added rightmost to the table.)r$   tblGridadd_gridColwtr_lstadd_tcwidth_Column)r&   r2   r-   gridColtrtcs         r*   
add_columnzTable.add_column%   s`    ))##%%'	))"" 	BBBH	 w%%r+   c                    | j                   }|j                         }|j                  j                  D ]0  }|j	                         }|j
                   |j
                  |_        2 t        ||       S )z?Return a |_Row| instance, newly added bottom-most to the table.)r$   add_trr-   gridCol_lstr1   r/   r2   _Row)r&   r'   r5   r4   r6   s        r*   add_rowzTable.add_row/   s]    iiZZ\{{.. 	%GByy$"99	% B~r+   c                .    | 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.alignment9   s     {{$$$r+   c                &    || j                   _        y r    r>   r&   values     r*   r@   zTable.alignmentC   s     %r+   c                .    | 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?   autofitrA   s    r*   rG   zTable.autofitG   s     {{"""r+   c                &    || j                   _        y r    rF   rC   s     r*   rG   zTable.autofitQ   s    #r+   c                D    ||| 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&   row_idxcol_idxcell_idxs       r*   cellz
Table.cellU   s(    
 g(:(::;{{8$$r+   c                    | j                   }t        |t        |      | j                        }|D cg c]  }||   	 c}S c c}w )z>Sequence of cells in the column at `column_idx` in this table.)rL   rangelenrK   )r&   
column_idxcellsidxsidxs        r*   column_cellszTable.column_cells]   s;    ZUT-?-?@&*+sc
+++s   A c                .    t        | j                  |       S )zG|_Columns| instance representing the sequence of columns in this table.)_Columnsr$   rA   s    r*   columnszTable.columnsc   s     		4((r+   c                L    | j                   }||z  }||z   }| j                  || S )zDEPRECATED: Use `table.rows[row_idx].cells` instead.

        Sequence of cells in the row at `row_idx` in this table.
        rJ   )r&   rM   column_countstartends        r*   	row_cellszTable.row_cellsh   s4    
 )),&l"{{5%%r+   c                .    t        | j                  |       S )z?|_Rows| instance containing the sequence of rows in this table.)_Rowsr$   rA   s    r*   rowsz
Table.rowsr   s     TYY%%r+   c                    | j                   j                  }t        d| 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`.
        _TableStyle | None)r$   tblStyle_valr   part	get_styler
   TABLE)r&   style_ids     r*   stylezTable.stylew   s8     99))($))*=*=hH[H[*\]]r+   c                z    | j                   j                  |t        j                        }|| j                  _        y r    )rg   get_style_idr
   ri   r$   rf   )r&   style_or_namerj   s      r*   rk   zTable.style   s*    99))-9L9L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.
         rA   s    r*   tablezTable.table   s	     r+   c                B    t        d| 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.
        WD_TABLE_DIRECTION | None)r   r$   bidiVisual_valrA   s    r*   table_directionzTable.table_direction   s     /1I1IJJr+   c                &    || j                   _        y r    )r#   rt   rC   s     r*   ru   zTable.table_direction   s    ',$r+   c                d   | j                   }g }| j                  j                         D ]  }t        |j                        D ]j  }|j
                  t        j                  k(  r|j                  ||           6|dkD  r|j                  |d          P|j                  t        ||              l  |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_tcsrR   	grid_spanvMerger   CONTINUEappend_Cell)r&   	col_countrU   r6   grid_span_idxs        r*   rL   zTable._cells   s     &&	))$$& 	2B!&r||!4 299 1 11LL	z!23"Q&LLr+LLr412	2 r+   c                .    | j                   j                  S )z)The number of grid columns in this table.)r$   r   rA   s    r*   rK   zTable._column_count   s     yy"""r+   c                .    | j                   j                  S r    )r$   tblPrrA   s    r*   r?   zTable._tblPr   s    yyr+   )r'   r   r(   t.ProvidesStoryPart)r2   r   )returnWD_TABLE_ALIGNMENT | None)rD   r   )r   bool)rD   r   )rM   intrN   r   r   r~   )rT   r   r   list[_Cell])rM   r   r   r   )r   rb   )r   re   )rn   z_TableStyle | str | None)r   rs   )rD   rs   )r   r   )r   r   )__name__
__module____qualname____doc__r"   r7   r<   propertyr@   setterrG   rP   rX   r   r[   r`   rc   rk   rq   ru   rL   rK   r?   __classcell__r)   s   @r*   r   r      sT   A
& % % & & # # ^^$ $%, ) )& & & ^ ^ \\* *   K K - -  $ # #  r+   r   c                  0    e Zd ZdZd fdZdd fdZ	 	 	 	 	 	 d fdZedd       ZddZ	e fd       Z
e fd       Zedd	       Zej                  dd
       Zed        Zej                  dd       Zed        Zej                  dd       Z xZS )r~   zTable cell.c                l    t         t        |   |t        d|             || _        |x| _        | _        y )Nr   )r!   r~   r"   r   _parent_tcr#   )r&   r6   r(   r)   s      r*   r"   z_Cell.__init__   s1    eT#B-BF(KL#%%4=r+   c                ,    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!   r~   add_paragraph)r&   textrk   r)   s      r*   r   z_Cell.add_paragraph   s     UD/e<<r+   c                    | j                   | j                   n
t        d      }t        t        |   |||      }| j                          |S )a  Return 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.
           )r2   r   r!   r~   	add_tabler   )r&   rc   colsr2   rq   r)   s        r*   r   z_Cell.add_table   sC     #jj4

&)eT,T4?r+   c                .    | j                   j                  S )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   rz   rA   s    r*   rz   z_Cell.grid_span   s     xx!!!r+   c                    | j                   |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   merger~   r   )r&   
other_cellr6   tc_2	merged_tcs        r*   r   z_Cell.merge   s3     88Z^^DHHTN	Y--r+   c                     t         t        | 
  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!   r~   
paragraphsr&   r)   s    r*   r   z_Cell.paragraphs   s     UD,,r+   c                     t         t        | 
  S )zRList of tables in the cell, in the order they appear.

        Read-only.
        )r!   r~   tablesr   s    r*   r   z_Cell.tables   s     UD((r+   c                F    dj                  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  4   K   | ]  }|j                     y wr    )r   ).0ps     r*   	<genexpr>z_Cell.text.<locals>.<genexpr>  s     9A9s   )joinr   rA   s    r*   r   z
_Cell.text  s     yy9999r+   c                    | j                   }|j                          |j                         }|j                         }||_        y)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   r6   r   rs        r*   r   z
_Cell.text  s6     XX
HHJGGIr+   c                L    | j                   j                  }|y|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%     }}!!<r+   c                F    | j                   j                         }||_        y r    )r#   get_or_add_tcPrr   )r&   rD   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   r2   rA   s    r*   r2   z_Cell.width0  s     xx~~r+   c                &    || j                   _        y r    r   rC   s     r*   r2   z_Cell.width5  s    r+   )r6   r   r(   r   ) N)r   strrk   zstr | ParagraphStyle | None)rc   r   r   r   r   r   r   r   )r   r~   )r   r   )r   r   )rD   z!WD_CELL_VERTICAL_ALIGNMENT | None)rD   r   )r   r   r   r   r"   r   r   r   rz   r   r   r   r   r   r   r2   r   r   s   @r*   r~   r~      s    &
="	 " ". - - ) ) : : 
[[
 
 
 
       \\ r+   r~   c                       e Zd ZdZd fdZed	d       Zed
d       Zedd       Zej                  dd       Zed        Z
 xZS )r3   zTable column.c                H    t         t        |   |       || _        || _        y r    )r!   r3   r"   r   _gridCol)r&   r4   r(   r)   s      r*   r"   z_Column.__init__=  s     gt%f-r+   c                ^    t        | j                  j                  | j                              S )zDSequence of |_Cell| instances corresponding to cells in this column.)tuplerq   rX   _indexrA   s    r*   rU   z_Column.cellsB  s"     TZZ,,T[[9::r+   c                .    | j                   j                  S )z7Reference to the |Table| object this column belongs to.r   rq   rA   s    r*   rq   z_Column.tableG       ||!!!r+   c                .    | j                   j                  S )zGThe width of this column in EMU, or |None| if no explicit width is set.r   r/   rA   s    r*   r2   z_Column.widthL  s     }}r+   c                &    || j                   _        y r    r   rC   s     r*   r2   z_Column.widthQ  s    r+   c                .    | j                   j                  S )z6Index of this column in its table, starting from zero.)r   gridCol_idxrA   s    r*   r   z_Column._indexU  s     }}(((r+   )r4   r   r(   r   r   ztuple[_Cell, ...]r   r   r   Length | NonerD   r   )r   r   r   r   r"   r   rU   rq   r2   r   r   r   r   s   @r*   r3   r3   :  ss     
 ; ; " "   \\    ) )r+   r3   c                  Z     e Zd ZdZd fdZd	dZd Zd Zed
d       Z	ed        Z
 xZS )rZ   zSequence of |_Column| instances corresponding to the columns in a table.

    Supports ``len()``, iteration and indexed access.
    c                H    t         t        |   |       || _        || _        y r    )r!   rZ   r"   r   r$   r%   s      r*   r"   z_Columns.__init__a  s     h&v.	r+   c                t    	 | j                   |   }t        ||       S # t        $ r d|z  }t        |      w xY w)z*Provide indexed access, e.g. 'columns[0]'.z!column index [%d] is out of range)_gridCol_lst
IndexErrorr3   )r&   rW   r4   msgs       r*   __getitem__z_Columns.__getitem__f  sK    	"'',G w%%  	"5;CS/!	"s    7c              #  J   K   | j                   D ]  }t        ||         y wr    )r   r3   )r&   r4   s     r*   __iter__z_Columns.__iter__o  s(     (( 	)G'4((	)s   !#c                ,    t        | j                        S r    )rS   r   rA   s    r*   __len__z_Columns.__len__s  s    4$$%%r+   c                .    | j                   j                  S )zBReference to the |Table| object this column collection belongs to.r   rA   s    r*   rq   z_Columns.tablev  r   r+   c                F    | j                   j                  }|j                  S )zfSequence containing ``<w:gridCol>`` elements for this table, each
        representing a table column.)r$   r-   r:   )r&   r-   s     r*   r   z_Columns._gridCol_lst{  s     ))##"""r+   r'   r   r(   r   )rW   r   r   )r   r   r   r   r"   r   r   r   r   rq   r   r   r   s   @r*   rZ   rZ   [  sD    

&)& " " # #r+   rZ   c                       e Zd ZdZd fdZedd       Zedd       Zedd       Zedd       Z	e	j                  dd       Z	edd       Zej                  dd	       Zedd
       Zedd       Z xZS )r;   z
Table row.c                V    t         t        |   |       || _        |x| _        | _        y r    )r!   r;   r"   r   _trr#   )r&   r5   r(   r)   s      r*   r"   z_Row.__init__  s'    dD"6*#%%4=r+   c                B     d fdd fd}t         |             S )a  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     K   | j                   dk(  r | j                        E d{    yt        | j                        }t	        | j
                        D ]  }|  y7 :w)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~   rq   rR   rz   )r6   rP   _iter_tc_cellsr&   s      r*   r   z!_Row.cells.<locals>.iter_tc_cells  s^      yyJ&(666 TZZ(D2<<( 
 7s   %A%A#;A%c               3  h   K   j                   j                  D ]  }  |       E d{     y7 w)zJGenerate `_Cell` instance for each populated layout-grid cell in this row.N)r   tc_lst)r6   r   r&   s    r*   _iter_row_cellsz#_Row.cells.<locals>._iter_row_cells  s/     hhoo -(,,,-,s   %202)r6   r   r   Iterator[_Cell])r   r   )r   )r&   r   r   s   ` @r*   rU   z
_Row.cells  s    	.	-
 _&''r+   c                .    | j                   j                  S )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_afterrA   s    r*   grid_cols_afterz_Row.grid_cols_after  s     xx"""r+   c                .    | j                   j                  S )a  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_beforerA   s    r*   grid_cols_beforez_Row.grid_cols_before  s     xx###r+   c                .    | j                   j                  S )znReturn a |Length| object representing the height of this cell, or |None| if
        no explicit height is set.r   trHeight_valrA   s    r*   heightz_Row.height  s     xx$$$r+   c                &    || j                   _        y r    r   rC   s     r*   r   z_Row.height  s     %r+   c                .    | j                   j                  S )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_hRulerA   s    r*   height_rulez_Row.height_rule  s     xx&&&r+   c                &    || j                   _        y r    r   rC   s     r*   r   z_Row.height_rule  s    "'r+   c                .    | j                   j                  S )z4Reference to the |Table| object this row belongs to.r   rA   s    r*   rq   z
_Row.table  r   r+   c                .    | j                   j                  S )z3Index of this row in its table, starting from zero.)r   tr_idxrA   s    r*   r   z_Row._index  s     xxr+   )r5   r   r(   r   r   r   r   r   )r   WD_ROW_HEIGHT_RULE | None)rD   r  r   )r   r   r   r   r"   r   rU   r   r   r   r   r   rq   r   r   r   s   @r*   r;   r;     s    &
 *( *(X # #  $ $  % %
 ]]& & ' ' ( ( " "  r+   r;   c                  n     e Zd ZdZd	 fdZed
d       Zedd       ZddZd Zd Ze	dd       Z
 xZS )rb   zSequence of |_Row| objects corresponding to the rows in a table.

    Supports ``len()``, iteration, indexed access, and slicing.
    c                H    t         t        |   |       || _        || _        y r    )r!   rb   r"   r   r$   r%   s      r*   r"   z_Rows.__init__  s     eT#F+	r+   c                     y r    rp   r&   rW   s     r*   r   z_Rows.__getitem__  s    -0r+   c                     y r    rp   r  s     r*   r   z_Rows.__getitem__	  s    58r+   c                    t        |       |   S )z7Provide indexed access, (e.g. `rows[0]` or `rows[1:3]`))listr  s     r*   r   z_Rows.__getitem__  s    Dz#r+   c                B      fd j                   j                  D        S )Nc              3  6   K   | ]  }t        |        y wr    )r;   )r   r5   r&   s     r*   r   z!_Rows.__iter__.<locals>.<genexpr>  s     :2R:s   )r$   r0   rA   s   `r*   r   z_Rows.__iter__  s    :)9)9::r+   c                @    t        | j                  j                        S r    )rS   r$   r0   rA   s    r*   r   z_Rows.__len__  s    499##$$r+   c                .    | j                   j                  S )z?Reference to the |Table| object this row collection belongs to.r   rA   s    r*   rq   z_Rows.table  r   r+   r   )rW   r   r   r;   )rW   slicer   z
list[_Row])rW   zint | slicer   z_Row | list[_Row]r   )r   r   r   r   r"   r   r   r   r   r   rq   r   r   s   @r*   rb   rb     sN    

 0 08 8;% " "r+   rb   )/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~   r3   rZ   r;   rb   rp   r+   r*   <module>r     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+   