XjLxUdZddlmZddlmZmZmZmZddlm 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.y )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 TableParentceZdZdZdfd ZddZdZeddZejddZeddZ e jddZ dd Z dd Z e d Zdd Ze dd Zed dZejd!dZedZed"dZejd#dZed$dZedZed%dZxZS)&Tablez7Proxy class for a WordprocessingML ```` element.cHtt| |||_||_yN)superr__init___element_tblselftblparent __class__s ^/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/docx/table.pyr"zTable.__init__ s  eT#F+  c|jj}|j}||_|jjD]}|j }||_t||S)zIReturn a |_Column| object of `width`, newly added rightmost to the table.)r$tblGrid add_gridColwtr_lstadd_tcwidth_Column)r&r2r-gridColtrtcs r* add_columnzTable.add_column%s`))##%%' ))"" BBBH w%%r+c|j}|j}|jjD]0}|j }|j  |j |_2t||S)z?Return a |_Row| instance, newly added bottom-most to the table.)r$add_trr- gridCol_lstr1r/r2_Row)r&r'r5r4r6s r*add_rowz Table.add_row/s]ii ZZ\{{.. %GByy$"99 %B~r+c.|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*r@zTable.alignment9s{{$$$r+c&||j_yr r>r&values r*r@zTable.alignmentCs % r+c.|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. r?autofitrAs r*rGz Table.autofitGs{{"""r+c&||j_yr rFrCs r*rGz Table.autofitQs# r+cD|||jzz}|j|S)zb|_Cell| at `row_idx`, `col_idx` intersection. (0, 0) is the top, left-most cell.  _column_count_cells)r&row_idxcol_idxcell_idxs r*cellz Table.cellUs( g(:(::;{{8$$r+c|j}t|t||j}|Dcgc]}|| c}Scc}w)z>Sequence of cells in the column at `column_idx` in this table.)rLrangelenrK)r& column_idxcellsidxsidxs r* column_cellszTable.column_cells]s; ZUT-?-?@&*+sc +++s Ac.t|j|S)zG|_Columns| instance representing the sequence of columns in this table.)_Columnsr$rAs r*columnsz Table.columnscs 4((r+cL|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. rJ)r&rM column_countstartends r* row_cellszTable.row_cellshs4 )) ,&l"{{5%%r+c.t|j|S)z?|_Rows| instance containing the sequence of rows in this table.)_Rowsr$rAs r*rowsz Table.rowsrsTYY%%r+c|jj}td|jj |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_valrpart get_styler TABLE)r&style_ids r*stylez Table.stylews899))($))*=*=h H[H[*\]]r+cz|jj|tj}||j_yr )rg get_style_idr rir$rf)r& style_or_namerjs r*rkz Table.styles*99))-9L9LM!) 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. rAs r*tablez Table.tables  r+cBtd|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. WD_TABLE_DIRECTION | None)rr$bidiVisual_valrAs r*table_directionzTable.table_directions/1I1IJJr+c&||j_yr )r#rtrCs r*ruzTable.table_directions', $r+cd|j}g}|jjD]}t|jD]j}|j t jk(r|j|| 6|dkDr|j|dP|jt||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) rKr$iter_tcsrR grid_spanvMerger CONTINUEappend_Cell)r& col_countrUr6 grid_span_idxs r*rLz Table._cellss&& ))$$& 2B!&r||!4 2 99 1 11LL z!23"Q&LLr+LLr41  2 2 r+c.|jjS)z)The number of grid columns in this table.)r$rrAs r*rKzTable._column_countsyy"""r+c.|jjSr )r$tblPrrAs r*r?z Table._tblPrsyyr+)r'rr(t.ProvidesStoryPart)r2r)returnWD_TABLE_ALIGNMENT | None)rDr)rbool)rDr)rMintrNrrr~)rTrr list[_Cell])rMrrr)rrb)rre)rnz_TableStyle | str | None)rrs)rDrs)rr)rr)__name__ __module__ __qualname____doc__r"r7r<propertyr@setterrGrPrXrr[r`rcrkrqrurLrKr? __classcell__r)s@r*rrsTA &%%&&## ^^$$%, ))&&& ^ ^ \\**KK--$##r+rc0eZdZdZdfd Zddfd Z dfd ZeddZddZ efdZ efdZ edd Z e jdd Z ed Zejdd Zed ZejddZxZS)r~z Table cell.cltt| |td|||_|x|_|_y)Nr)r!r~r"r_parent_tcr#)r&r6r(r)s r*r"z_Cell.__init__s1 eT#B-BF(KL #%%4=r+c,tt| ||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!r~ add_paragraph)r&textrkr)s r*rz_Cell.add_paragraphsUD/e<z_Cell.text..s9A9s)joinrrAs r*rz _Cell.textsyy9999r+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_contentadd_padd_rr)r&rr6rrs r*rz _Cell.texts6XX  HHJ GGIr+cL|jj}|y|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%}}!! <r+cF|jj}||_yr )r#get_or_add_tcPrr)r&rDrs r*rz_Cell.vertical_alignment+s}},,.r+c.|jjS)zEThe width of this cell in EMU, or |None| if no explicit width is set.rr2rAs r*r2z _Cell.width0sxx~~r+c&||j_yr rrCs r*r2z _Cell.width5s r+)r6rr(r)N)rstrrkzstr | ParagraphStyle | None)rcrrrrrrr)rr~)rr)rr)rDz!WD_CELL_VERTICAL_ALIGNMENT | None)rDr)rrrrr"rrrrzrrrrrrr2rrs@r*r~r~s& =  "   "".--)):: [[       \\r+r~ceZdZdZdfd Zed dZed dZed dZejd dZedZ xZ S) r3z Table column.cHtt| |||_||_yr )r!r3r"r_gridCol)r&r4r(r)s r*r"z_Column.__init__=s  gt%f-  r+c^t|jj|jS)zDSequence of |_Cell| instances corresponding to cells in this column.)tuplerqrX_indexrAs r*rUz _Column.cellsBs"TZZ,,T[[9::r+c.|jjS)z7Reference to the |Table| object this column belongs to.rrqrAs r*rqz _Column.tableG||!!!r+c.|jjS)zGThe width of this column in EMU, or |None| if no explicit width is set.rr/rAs r*r2z _Column.widthLs}}r+c&||j_yr rrCs r*r2z _Column.widthQs  r+c.|jjS)z6Index of this column in its table, starting from zero.)r gridCol_idxrAs r*rz_Column._indexUs}}(((r+)r4r r(rrztuple[_Cell, ...]rrr Length | NonerDr) rrrrr"rrUrqr2rrrrs@r*r3r3:ss ;;"" \\  ))r+r3cZeZdZdZdfd Zd dZdZdZed dZ edZ xZ S) rZzSequence of |_Column| instances corresponding to the columns in a table. Supports ``len()``, iteration and indexed access. cHtt| |||_||_yr )r!rZr"rr$r%s r*r"z_Columns.__init__as  h&v.  r+ct |j|}t||S#t$rd|z}t|wxYw)z*Provide indexed access, e.g. 'columns[0]'.z!column index [%d] is out of range) _gridCol_lst IndexErrorr3)r&rWr4msgs r* __getitem__z_Columns.__getitem__fsK "'',Gw%% "5;CS/ ! "s7c#JK|jD]}t||ywr )rr3)r&r4s r*__iter__z_Columns.__iter__os((( )G'4( ( )s!#c,t|jSr )rSrrAs r*__len__z_Columns.__len__ss4$$%%r+c.|jjS)zBReference to the |Table| object this column collection belongs to.rrAs r*rqz_Columns.tablevrr+cF|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+r'rr(r)rWrr) rrrrr"rrrrrqrrrs@r*rZrZ[sD  &)&""##r+rZceZdZdZd fd Zed dZeddZeddZeddZ e jddZ eddZ e jdd Z edd Z edd Z xZS)r;z Table row.cVtt| |||_|x|_|_yr )r!r;r"r_trr#)r&r5r(r)s r*r"z _Row.__init__s' dD"6* #%%4=r+cBdfd 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`. c3K|jdk(r|jEd{yt|j}t |j D]}|y7:w)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_abover~rqrRrz)r6rP_ iter_tc_cellsr&s r*rz!_Row.cells..iter_tc_cellss^yyJ&(666TZZ(D2<<(    7s%A%A#;A%c3hKjjD]}|Ed{y7w)zJGenerate `_Cell` instance for each populated layout-grid cell in this row.N)rtc_lst)r6rr&s r*_iter_row_cellsz#_Row.cells.._iter_row_cellss/hhoo -(,,, -,s %202)r6rrIterator[_Cell])rr)r)r&rrs` @r*rUz _Row.cellss . - _&''r+c.|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_afterrAs r*grid_cols_afterz_Row.grid_cols_aftersxx"""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_beforerAs r*grid_cols_beforez_Row.grid_cols_beforesxx###r+c.|jjS)znReturn a |Length| object representing the height of this cell, or |None| if no explicit height is set.r trHeight_valrAs r*heightz _Row.heightsxx$$$r+c&||j_yr rrCs r*rz _Row.heights %r+c.|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_hRulerAs r* height_rulez_Row.height_rules xx&&&r+c&||j_yr rrCs r*rz_Row.height_rules"'r+c.|jjS)z4Reference to the |Table| object this row belongs to.rrAs r*rqz _Row.tablerr+c.|jjS)z3Index of this row in its table, starting from zero.)rtr_idxrAs r*rz _Row._indexsxxr+)r5rr(rrrrr)rWD_ROW_HEIGHT_RULE | None)rDrr)rrrrr"rrUrrrrrrqrrrs@r*r;r;s& *(*(X## $$ %%  ]]&&''((""r+r;cneZdZdZd fd Zed dZed dZd dZdZdZe d dZ xZ S)rbzSequence of |_Row| objects corresponding to the rows in a table. Supports ``len()``, iteration, indexed access, and slicing. cHtt| |||_||_yr )r!rbr"rr$r%s r*r"z_Rows.__init__s  eT#F+  r+cyr rpr&rWs r*rz_Rows.__getitem__s-0r+cyr rprs r*rz_Rows.__getitem__ s58r+ct||S)z7Provide indexed access, (e.g. `rows[0]` or `rows[1:3]`))listrs r*rz_Rows.__getitem__ sDz#r+cBfdjjDS)Nc36K|]}t|ywr )r;)rr5r&s r*rz!_Rows.__iter__..s:2R:s)r$r0rAs`r*rz_Rows.__iter__s:)9)9::r+c@t|jjSr )rSr$r0rAs r*rz _Rows.__len__s499##$$r+c.|jjS)z?Reference to the |Table| object this row collection belongs to.rrAs r*rqz _Rows.tablerr+r)rWrrr;)rWslicerz list[_Row])rWz int | slicerz_Row | list[_Row]r) rrrrr"rrrrrrqrrs@r*rbrbsN  00 88;%""r+rb)/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__rr~r3rZr;rbrpr+r*rs3"::',)6*)BBZZ??" 4 Y3`J`Fw wt)h)B%#x%#Pu8up"H"r+