
    Pqh7                    0   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#y)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                  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        |   |       |x| _        | _        y N)superr   __init___element_tblselftblparent	__class__s      K/srv/www/ollama/chat-ollama/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   r*   r%   gridColtrtcs         r"   
add_columnzTable.add_column   s`    ))##%%'	))"" 	BBBH	 w%%r#   c                    | j                   }|j                         }|j                  j                  D ]#  }|j	                         }|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%   sS    iiZZ\{{.. 	!GByyBH	! 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"   r8   zTable.alignment.   s     {{$$$r#   c                &    || j                   _        y r   r6   r   values     r"   r8   zTable.alignment8   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.
        r7   autofitr9   s    r"   r?   zTable.autofit<   s     {{"""r#   c                &    || j                   _        y r   r>   r;   s     r"   r?   zTable.autofitF   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.cellJ   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.)rD   rangelenrC   )r   
column_idxcellsidxsidxs        r"   column_cellszTable.column_cellsR   s;    ZUT-?-?@&*+sc
+++s   A c                .    t        | j                  |       S )zG|_Columns| instance representing the sequence of columns in this table.)_Columnsr   r9   s    r"   columnszTable.columnsX   s     		4((r#   c                L    | j                   }||z  }||z   }| j                  || S )z8Sequence of cells in the row at `row_idx` in this table.rB   )r   rE   column_countstartends        r"   	row_cellszTable.row_cells]   s2    )),&l"{{5%%r#   c                .    t        | j                  |       S )z?|_Rows| instance containing the sequence of rows in this table.)_Rowsr   r9   s    r"   rowsz
Table.rowsd   s     TYY%%r#   c                    | j                   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   s0     99))yy""8]-@-@AAr#   c                z    | j                   j                  |t        j                        }|| j                  _        y r   )r^   get_style_idr	   r`   r   r]   )r   style_or_namera   s      r"   rb   zTable.styley   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.
         r9   s    r"   tablezTable.table~   s	     r#   c                .    | 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_valr9   s    r"   table_directionzTable.table_direction   s     }}+++r#   c                &    || j                   _        y r   rj   r;   s     r"   rl   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   )
rC   r   iter_tcsrJ   	grid_spanvMerger
   CONTINUEappend_Cell)r   	col_countrM   r.   grid_span_idxs        r"   rD   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   rv   r9   s    r"   rC   zTable._column_count   s     yy"""r#   c                .    | j                   j                  S r   )r   tblPrr9   s    r"   r7   zTable._tblPr   s    yyr#   )r   r   r    zt.StoryChild)r*   r   )returnWD_TABLE_ALIGNMENT | None)r<   r|   )r{   bool)r<   r}   )rE   intrF   r~   r{   ru   )rL   r~   r{   List[_Cell])rE   r~   r{   r   )r{   rZ   )r{   _TableStyle | None)re   r   )r{   WD_TABLE_DIRECTION | None)r<   r   )r{   r   )r{   r   )__name__
__module____qualname____doc__r   r/   r4   propertyr8   setterr?   rH   rP   r   rS   rX   r[   rb   rh   rl   rD   rC   r7   __classcell__r!   s   @r"   r   r      sR   A(& % % & & # # ^^$ $%, ) )& & & B B \\* *   , , - -  $ # #  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 )ru   zTable cell.c                J    t         t        |   ||       |x| _        | _        y r   )r   ru   r   _tcr   )r   r.   r    r!   s      r"   r   z_Cell.__init__   s"    eT#B/#%%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   ru   add_paragraph)r   textrb   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,
        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.
           )r*   r   r   ru   	add_tabler   )r   r[   colsr*   rh   r!   s        r"   r   z_Cell.add_table   sC     #jj4

&)eT,T4?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   mergeru   _parent)r   
other_cellr.   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   ru   
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   ru   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   r9   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   r.   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   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*   r9   s    r"   r*   z_Cell.width  s     xx~~r#   c                &    || j                   _        y r   r   r;   s     r"   r*   z_Cell.width  s    r#   ) N)r{   str)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r*   r   r   s   @r"   ru   ru      s    &=
. - - ) ) : : 
[[
 
 
 
       \\ r#   ru   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                :    t         t        |   |       || _        y r   )r   r+   r   _gridCol)r   r,   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.)tuplerh   rP   _indexr9   s    r"   rM   z_Column.cells&  s"     TZZ,,T[[9::r#   c                .    | j                   j                  S )z7Reference to the |Table| object this column belongs to.r   rh   r9   s    r"   rh   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'   r9   s    r"   r*   z_Column.width0  s     }}r#   c                &    || j                   _        y 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_idxr9   s    r"   r   z_Column._index9  s     }}(((r#   )r   r   r   r   r   r   rM   rh   r*   r   r   r   r   s   @r"   r+   r+     ss      ; ; " "   \\    ) )r#   r+   c                  T     e Zd ZdZ fdZd Zd Zd Zed        Z	ed        Z
 xZS )rR   zSequence of |_Column| instances corresponding to the columns in a table.

    Supports ``len()``, iteration and indexed access.
    c                :    t         t        |   |       || _        y r   )r   rR   r   r   r   s      r"   r   z_Columns.__init__E  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
IndexErrorr+   )r   rO   r,   msgs       r"   __getitem__z_Columns.__getitem__I  sK    	"'',G w%%  	"5;CS/!	"s    7c              #  J   K   | j                   D ]  }t        ||         y wr   )r   r+   )r   r,   s     r"   __iter__z_Columns.__iter__R  s(     (( 	)G'4((	)s   !#c                ,    t        | j                        S r   )rK   r   r9   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   r9   s    r"   rh   z_Columns.tableY  r   r#   c                F    | j                   j                  }|j                  S )zfSequence containing ``<w:gridCol>`` elements for this table, each
        representing a table column.)r   r%   r2   )r   r%   s     r"   r   z_Columns._gridCol_lst^  s     ))##"""r#   )r   r   r   r   r   r   r   r   r   rh   r   r   r   s   @r"   rR   rR   ?  sD    
&)& " " # #r#   rR   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 )r3   z
Table row.c                H    t         t        |   |       |x| _        | _        y r   )r   r3   r   _trr   )r   r-   r    r!   s      r"   r   z_Row.__init__i  s     dD"6*#%%4=r#   c                ^    t        | j                  j                  | j                              S )zASequence of |_Cell| instances corresponding to cells in this row.)r   rh   rX   r   r9   s    r"   rM   z
_Row.cellsm  s"     TZZ))$++6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_valr9   s    r"   heightz_Row.heightr  s     xx$$$r#   c                &    || j                   _        y 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_hRuler9   s    r"   height_rulez_Row.height_rule|  s     xx&&&r#   c                &    || j                   _        y 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   r9   s    r"   rh   z
_Row.table  r   r#   c                .    | j                   j                  S )z3Index of this row in its table, starting from zero.)r   tr_idxr9   s    r"   r   z_Row._index  s     xxr#   )r{   zTuple[_Cell])r   r   r   r   r   r   rM   r   r   r   rh   r   r   r   s   @r"   r3   r3   f  s    & 8 8 % %
 ]]& & ' '
 ( ( " "  r#   r3   c                  j     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 )rZ   zSequence of |_Row| objects corresponding to the rows in a table.

    Supports ``len()``, iteration, indexed access, and slicing.
    c                :    t         t        |   |       || _        y r   )r   rZ   r   r   r   s      r"   r   z_Rows.__init__  s    eT#F+	r#   c                     y r   rg   r   rO   s     r"   r   z_Rows.__getitem__      r#   c                     y r   rg   r   s     r"   r   z_Rows.__getitem__  r   r#   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   )r3   )r   r-   r   s     r"   r   z!_Rows.__iter__.<locals>.<genexpr>  s     :2R:s   )r   r(   r9   s   `r"   r   z_Rows.__iter__  s    :)9)9::r#   c                @    t        | j                  j                        S r   )rK   r   r(   r9   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   r9   s    r"   rh   z_Rows.table  r   r#   )rO   r~   r{   r3   )rO   slicer{   z
List[_Row])rO   zint | slicer{   z_Row | List[_Row])r   r   r   r   r   r   r   r   r   r   rh   r   r   s   @r"   rZ   rZ     sX    
    ;% " "r#   rZ   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   ru   r+   rR   r3   rZ   rg   r#   r"   <module>r      s    3 " 7 7 , ) * 6 6F0"-[H [|j jZ)h )@$#x $#N(8 (V"H "r#   