;iLUdZddlmZddlmZmZmZmZddlm Z ddl m Z ddl m Z ddlmZddlmZdd lmZdd lmZmZmZmZer*dd lmZdd lmZmZmZdd lmZm Z m!Z!m"Z"ddlm#Z#ddl$m%Z%m&Z&dZ'de(d<GddeZ)Gdde Z*GddeZ+GddeZ,GddeZ-GddeZ.d S)z-The |Table| object and related proxy classes.) annotations) TYPE_CHECKINGIteratorcastoverload) TypeAlias)BlockItemContainer) WD_STYLE_TYPE)WD_CELL_VERTICAL_ALIGNMENT)ST_Merge) CT_TblGridCol)InchesParented StoryChild lazypropertyN)WD_ROW_HEIGHT_RULEWD_TABLE_ALIGNMENTWD_TABLE_DIRECTION)CT_RowCT_TblCT_TblPrCT_Tc)Length)ParagraphStyle _TableStylezTable | _Columns | _Rowsr TableParentceZdZdZd,fd Zd-d Zd Zed.d Zej d/dZed0dZ e j d1dZ d2dZ d3dZ e dZd4dZe d5dZed6d Zej d7d#Zed$Zed8d&Zej d9d'Zed:d(Zed)Zed;d+ZxZS)<Tablez7Proxy class for a WordprocessingML ```` element.tblrparentt.ProvidesStoryPartcttt||||_||_dSN)superr__init___element_tblselfrr __class__s >C:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\docx/table.pyr%zTable.__init__ s3 eT##F+++  widthrc|jj}|}||_|jjD]}|}||_t||S)zIReturn a |_Column| object of `width`, newly added rightmost to the table.)r'tblGrid add_gridColwtr_lstadd_tcr-_Column)r)r-r/gridColtrtcs r+ add_columnzTable.add_column%s^)#%%'' )"  BBBHHw%%%r,c|j}|}|jjD])}|}|j |j|_*t||S)z?Return a |_Row| instance, newly added bottom-most to the table.)r'add_trr/ gridCol_lstr3r1r-_Row)r)rr6r5r7s r+add_rowz Table.add_row/sWi ZZ\\{. % %GBy$"9B~~r,returnWD_TABLE_ALIGNMENT | Nonec|jjS)aRead/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 alignmentr)s r+rCzTable.alignment9s{$$r,valuec||j_dSr#rAr)rEs r+rCzTable.alignmentCs % r,boolc|jjS)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. rBautofitrDs r+rKz Table.autofitGs{""r,c||j_dSr#rJrGs r+rKz Table.autofitQs# r,row_idxintcol_idx_Cellc6|||jzz}|j|S)zb|_Cell| at `row_idx`, `col_idx` intersection. (0, 0) is the top, left-most cell.  _column_count_cells)r)rMrOcell_idxs r+cellz Table.cellUs# g(::;{8$$r, column_idx list[_Cell]ct|jt|t|j}fd|DS)z>Sequence of cells in the column at `column_idx` in this table.c g|] }| Sr[).0idxcellss r+ z&Table.column_cells..as+++sc +++r,)rTrangelenrS)r)rWidxsr^s @r+ column_cellszTable.column_cells]s> ZUT-?@@++++d++++r,c,t|j|S)zG|_Columns| instance representing the sequence of columns in this table.)_Columnsr'rDs r+columnsz Table.columnscs 4(((r,cB|j}||z}||z}|j||S)zDEPRECATED: Use `table.rows[row_idx].cells` instead. Sequence of cells in the row at `row_idx` in this table. rR)r)rM column_countstartends r+ row_cellszTable.row_cellshs1 ) ,&l"{59%%r,_Rowsc,t|j|S)z?|_Rows| instance containing the sequence of rows in this table.)rlr'rDs r+rowsz Table.rowsrsTY%%%r,_TableStyle | Nonec|jj}td|j|t jS)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`. ro)r' tblStyle_valrpart get_styler TABLE)r)style_ids r+stylez Table.stylews49)($)*=*=h H[*\*\]]]r, style_or_name_TableStyle | str | Nonech|j|tj}||j_dSr#)rr get_style_idr rtr'rq)r)rwrus r+rvz Table.styles,9))-9LMM!) r,c|S)aProvide 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. r[rDs r+tablez Table.tables  r,WD_TABLE_DIRECTION | Nonec6td|jjS)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})rr'bidiVisual_valrDs r+table_directionzTable.table_directions/1IJJJr,c||j_dSr#)r&rrGs r+rzTable.table_directions', $$$r,cl|j}g}|jD]}t|jD]y}|jt jkr||| 4|dkr||dV|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) rSr'iter_tcsr` grid_spanvMerger CONTINUEappendrP)r) col_countr^r7 grid_span_idxs r+rTz Table._cellss& )$$&& 2 2B!&r|!4!4 2 2 9 111LL z!23333"Q&&LLr++++LLr41111  2 r,c|jjS)z)The number of grid columns in this table.)r'rrDs r+rSzTable._column_countsy""r,rc|jjSr#)r'tblPrrDs r+rBz Table._tblPrs yr,)rrr r!)r-r)r>r?)rEr?)r>rH)rErH)rMrNrOrNr>rP)rWrNr>rX)rMrNr>rX)r>rl)r>ro)rwrx)r>r})rEr})r>rX)r>r)__name__ __module__ __qualname____doc__r%r8r=propertyrCsetterrKrVrcrrfrkrnrvr|rrTrSrB __classcell__r*s@r+rrsgAA &&&&%%%X%&&&&###X# ^$$$^$%%%%,,,, ))\)&&&&&&&\& ^ ^ ^X ^ \***\*XKKKXK----X$##X#Xr,rc<eZdZdZd"fd Zd#d$fd Zd%fd Zed&dZd'dZ efdZ efdZ ed(dZ e j d)dZ edZej d*dZedZej d+d!ZxZS),rPz Table cell.r7rr rctt||td|||_|x|_|_dS)Nr!)r$rPr%r_parent_tcr&)r)r7r r*s r+r%z_Cell.__init__sG eT##B-BF(K(KLLL #%%4===r,Ntextstrrvstr | ParagraphStyle | NonecVtt|||S)aReturn 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$rP add_paragraph)r)rrvr*s r+rz_Cell.add_paragraphs%UD!!//e<<rc|j|jntd}tt||||}||S)aReturn 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. N)r-rr$rP add_tabler)r)rnrr-r|r*s r+rz_Cell.add_tablesU#j4 &))eT"",,T4??  r,c|jjS)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. )rrrDs r+rz_Cell.grid_spansx!!r, other_cellcr|j|j}}||}t||jS)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. )rmergerPr)r)rr7tc_2 merged_tcs r+rz _Cell.merges2 8Z^DHHTNN Y ---r,c8tt|jS)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$rP paragraphsr)r*s r+rz_Cell.paragraphssUD!!,,r,c8tt|jS)zRList of tables in the cell, in the order they appear. Read-only. )r$rPtablesrs r+rz _Cell.tabless UD!!((r,cJdd|jDS)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.  c3$K|] }|jV dSr#)r)r\ps r+ z_Cell.text..s$99A999999r,)joinrrDs r+rz _Cell.texts'yy99999999r,c|j}||}|}||_dS)zWrite-only. Set entire contents of cell to the string `text`. Any existing content or revisions are replaced. N)r clear_contentadd_padd_rr)r)rr7rrs r+rz _Cell.textsBX  HHJJ GGIIr,c0|jj}|dS|jS)aMember 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)rs r+vertical_alignmentz_Cell.vertical_alignments }! <4r,rE!WD_CELL_VERTICAL_ALIGNMENT | NonecF|j}||_dSr#)r&get_or_add_tcPrr)r)rErs r+rz_Cell.vertical_alignment+s },,..r,c|jjS)zEThe width of this cell in EMU, or |None| if no explicit width is set.rr-rDs r+r-z _Cell.width0sx~r,rc||j_dSr#rrGs r+r-z _Cell.width5sr,)r7rr r)rN)rrrvr)rnrNrrNr>rr>rN)rrP)r>r)rr)rEr)rEr)rrrrr%rrrrrrrrrrr-rrs@r+rPrPs&&&&&& = = = = = = =      """X"....----X-))))X):::X: [   [   X     X \\r,rPceZdZdZdfd Zedd Zedd Zedd Zej ddZedZ xZ S)r4z Table column.r5r r rcttt||||_||_dSr#)r$r4r%r_gridCol)r)r5r r*s r+r%z_Column.__init__=s3 gt%%f---  r,r>tuple[_Cell, ...]cZt|j|jS)zDSequence of |_Cell| instances corresponding to cells in this column.)tupler|rc_indexrDs r+r^z _Column.cellsBs$TZ,,T[99:::r,rc|jjS)z7Reference to the |Table| object this column belongs to.rr|rDs r+r|z _Column.tableG|!!r, Length | Nonec|jjS)zGThe width of this column in EMU, or |None| if no explicit width is set.rr1rDs r+r-z _Column.widthLs}r,rEc||j_dSr#rrGs r+r-z _Column.widthQs r,c|jjS)z6Index of this column in its table, starting from zero.)r gridCol_idxrDs r+rz_Column._indexUs}((r,)r5r r rr>rr>rr>rrEr) rrrrr%rr^r|r-rrrrs@r+r4r4:s      ;;;X;"""X"X \   \ ))X)))))r,r4cfeZdZdZdfd Zdd Zd Zd ZeddZ edZ xZ S)rezSequence of |_Column| instances corresponding to the columns in a table. Supports ``len()``, iteration and indexed access. rrr rcttt||||_||_dSr#)r$rer%rr'r(s r+r%z_Columns.__init__as3 h&&v...  r,r]rNc |j|}n"#t$rd|z}t|wxYwt||S)z*Provide indexed access, e.g. 'columns[0]'.z!column index [%d] is out of range) _gridCol_lst IndexErrorr4)r)r]r5msgs r+ __getitem__z_Columns.__getitem__fsY "',GG " " "5;CS// ! "w%%%s /c#BK|jD]}t||VdSr#)rr4)r)r5s r+__iter__z_Columns.__iter__os;( ) )G'4(( ( ( ( ( ) )r,c*t|jSr#)rarrDs r+__len__z_Columns.__len__ss4$%%%r,r>rc|jjS)zBReference to the |Table| object this column collection belongs to.rrDs r+r|z_Columns.tablevrr,c(|jj}|jS)zfSequence containing ```` elements for this table, each representing a table column.)r'r/r;)r)r/s r+rz_Columns._gridCol_lst{s)#""r,rrr r)r]rNr) rrrrr%rrrrr|rrrs@r+rere[s  &&&&)))&&&"""X"##X#####r,receZdZdZdfd Zedd Zedd Zedd ZeddZ e j ddZ eddZ e j ddZ eddZ eddZ xZS)r<z Table row.r6rr rctt||||_|x|_|_dSr#)r$r<r%r_trr&)r)r6r r*s r+r%z _Row.__init__s: dD""6*** #%%4===r,r>rcPdfd dfd }t|S) aSequence 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`. r7rr>Iterator[_Cell]c3K|jdkr|jEd{VdSt|j}t |jD]}|VdS)a^Generate a cell object for each layout-grid cell in `tc`. In particular, a `` 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_aboverPr|r`r)r7rV_ iter_tc_cellsr)s r+rz!_Row.cells..iter_tc_cellssyJ&&(=666666666TZ((D2<((     r,c3LKjjD]}|Ed{VdS)zJGenerate `_Cell` instance for each populated layout-grid cell in this row.N)rtc_lst)r7rr)s r+_iter_row_cellsz#_Row.cells.._iter_row_cellssIho - -(=,,,,,,,,,, - -r,)r7rr>r)r>r)r)r)rrs` @r+r^z _Row.cellssb       . - - - - - - - __&&'''r,rNc|jjS)aCount 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_afterrDs r+grid_cols_afterz_Row.grid_cols_aftersx""r,c|jjS)aCount 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_beforerDs r+grid_cols_beforez_Row.grid_cols_beforesx##r,rc|jjS)znReturn a |Length| object representing the height of this cell, or |None| if no explicit height is set.r trHeight_valrDs r+heightz _Row.heightsx$$r,rEc||j_dSr#rrGs r+rz _Row.heights %r,WD_ROW_HEIGHT_RULE | Nonec|jjS)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. rtrHeight_hRulerDs r+ height_rulez_Row.height_rules x&&r,c||j_dSr#rrGs r+rz_Row.height_rules"'r,rc|jjS)z4Reference to the |Table| object this row belongs to.rrDs r+r|z _Row.tablerr,c|jjS)z3Index of this row in its table, starting from zero.)rtr_idxrDs r+rz _Row._indexsxr,)r6rr rrrrr)r>r)rErr)rrrrr%rr^rrrrrr|rrrs@r+r<r<sj&&&&&& *(*(*(X*(X###X# $$$X$ %%%X%  ]&&&]&'''X'(((("""X"Xr,r<ceZdZdZdfd Zedd ZeddZddZdZdZe ddZ xZ S)rlzSequence of |_Row| objects corresponding to the rows in a table. Supports ``len()``, iteration, indexed access, and slicing. rrr rcttt||||_||_dSr#)r$rlr%rr'r(s r+r%z_Rows.__init__s3 eT##F+++  r,r]rNr>r<cdSr#r[r)r]s r+rz_Rows.__getitem__s-0Sr,slice list[_Row]cdSr#r[r s r+rz_Rows.__getitem__ s58Sr, int | slice_Row | list[_Row]c,t||S)z7Provide indexed access, (e.g. `rows[0]` or `rows[1:3]`))listr s r+rz_Rows.__getitem__ sDzz#r,c4fdjjDS)Nc38K|]}t|VdSr#)r<)r\r6r)s r+rz!_Rows.__iter__..s+::2R::::::r,)r'r2rDs`r+rz_Rows.__iter__s"::::)9::::r,c4t|jjSr#)rar'r2rDs r+rz _Rows.__len__s49#$$$r,rc|jjS)z?Reference to the |Table| object this row collection belongs to.rrDs r+r|z _Rows.tablerr,r)r]rNr>r<)r]r r>r )r]rr>rr) rrrrr%rrrrrr|rrs@r+rlrls  000X0 888X8;;;%%%"""X"""""r,rl)/r __future__rtypingrrrrtyping_extensionsr docx.blkcntnrr docx.enum.styler docx.enum.tabler docx.oxml.simpletypesr docx.oxml.tabler docx.sharedrrrr docx.typestypestrrrrrrrrdocx.styles.stylerrr__annotations__rrPr4rer<rlr[r,r+r%s333""""""::::::::::::'''''',,,,,,))))))666666******))))))BBBBBBBBBBBBZZZZZZZZZZ????????????"""""" 4 3333`````J```Fwwwww wwwt)))))h)))B%#%#%#%#%#x%#%#%#Puuuuu8uuup"""""H"""""r,