
    {-j                     >   d dl mZ ddlmZmZ ddlmZ  ed          rd dlmZ  ed          rd d	l	m
Z
 d d
lmZ  ed          rd dlmZ d Z ed          d             Z ed          dd            Zd Z edd          dd            ZddZd Zd ZdS )    )absolute_import   )function_requires_depsis_dep_available   Tablelxml)htmlopenpyxl)Workbook)get_column_letter	premailer)	Premailerc                 L    |                                  rt          |           S dS )z(
    Convert a string to an integer
    r   )isdigitint)ss    d/var/www/html/banglarbhumi/venv/lib/python3.11/site-packages/paddlex/inference/utils/io/tablepyxl.pystring_to_intr      s$     	yy{{ 1vv1    c                     t          j        |           }|                    d          }|D ]}|                                 d |                    d          D             S )z(
    Find all the tables in the doc
    z//comment()c                 ,    g | ]}t          |          S  r   ).0tables     r   
<listcomp>zget_Tables.<locals>.<listcomp>/   s    <<<UE%LL<<<r   z//table)r   
fromstringxpathdrop_tag)doctreecommentscomments       r   
get_Tablesr%   &   sh    
 ?3Dzz-((H  <<djj&;&;<<<<r   c           	         ddl m} |}|j        D ]}|j        D ]}|                     ||          }t          ||          r,|dz  }|                     ||          }t          ||          ,t          |j                            dd                    }	t          |j                            dd                    }
|
dk    s|	dk    r%| 	                    ||||
z   dz
  ||	z   dz
             |j
        |_
        |                    |           |                    d	          }|                    d
          }|	dk    rxt          | j        t          |                   j        pdt#          |j
                  dz             }|r	||k    r|}n
|r||k     r|}|| j        t          |                   _        ||	z  }|dz  }|}|S )z}
    Writes every tr child element of elem to a row in the worksheet
    returns the next row after all rows are written
    r   )
MergedCell)rowcolumnr   colspan1rowspan)	start_rowstart_columnend_row
end_columnz	min-widthz	max-width   )openpyxl.cell.cellr'   rowscellscell
isinstancer   elementgetmerge_cellsvalueformatget_dimensionmaxcolumn_dimensionsr   widthlen)	worksheetelemr(   r)   r'   initial_column	table_row
table_cellr5   r*   r,   	min_width	max_widthr?   s                 r   
write_rowsrH   2   s!    .-----NY &  & 	#/ #	 #	J>>c&>99DT:.. >! ~~#f~== T:.. > $J$6$:$:9c$J$JKKG#J$6$:$:9c$J$JKKG{{gkk%%!!''MA-%/!3	 &    $)DJd###"00==I"00==I!||
 /0A&0I0IJPUTU
())A-   &!2!2%EE &59#4#4%EOT	+,=f,E,EFLgFFqJr   c                     |                     | j                            d                    }t          | |dd           dS )z
    Takes a table and workbook and writes the table to a new sheet.
    The sheet title will be the same as the table attribute name.
    name)titler   N)create_sheetr7   r8   insert_table)r   wbwss      r   table_to_sheetrP   e   sA    
 
u}0088	9	9BAq!!!!!r   Nc                     |s(t                      }|                    |j                   t          | |d                                          }t          |          }|D ]}t          ||           |S )z
    Takes a string representation of an html document and writes one sheet for
    every table in the document.
    The workbook is returned
    F)base_urlremove_classes)r   removeactiver   	transformr%   rP   )r!   rN   rR   inline_styles_doctablesr   s         r   document_to_workbookrY   n   s      ZZ
		")!hu  ikk  )**F " "ub!!!!Ir   c                 R    t          | |          }|                    |           dS )z
    Takes a string representation of an html document and writes one sheet for
    every table in the document. The workbook is written out to a file called filename
    )rR   N)rY   save)r!   filenamerR   rN   s       r   document_to_xlr]      s.    
 
cH	5	5	5BGGHr   c                     | j         rt          || j         ||          }| j        rt          || j        ||          }dS dS )zL
    Inserts a table into the worksheet at the specified column and row
    N)headrH   body)r   rA   r)   r(   s       r   rM   rM      sP     z =EJV<<z =EJV<<= =r   c                 T    |j         }|j        |j        }}t          | |||           dS )zE
    Inserts a table at the location of an openpyxl Cell object.
    N)parentr)   r(   rM   )r   r5   rO   r)   r(   s        r   insert_table_at_cellrc      s2     
B+txCFFC(((((r   )r   )NN)N)
__future__r   
utils.depsr   r   styler	   r
   r   r   r   openpyxl.utilsr   r   r   r   r%   rH   rP   rY   r]   rM   rc   r   r   r   <module>rh      s   ' & & & & & C C C C C C C C      F J 1!!!!!!000000K   $######   = =  = 
##/ / / $#/d" " " 
K00   10*   = = =) ) ) ) )r   