
    9i                     *   S SK Jr  SSKJrJr  SSKJr  \" S5      (       a  S SKJr  \" S5      (       a  S S	K	J
r
  S S
KJr  \" S5      (       a  S SKJr  S r\" S5      S 5       r\" S5      SS j5       rS r\" SS5      SS j5       rSS jrS rS rg)    )absolute_import   )function_requires_depsis_dep_available   )Tablelxml)htmlopenpyxl)Workbook)get_column_letter	premailer)	Premailerc                 D    U R                  5       (       a  [        U 5      $ g)z 
Convert a string to an integer
r   )isdigitint)ss    d/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/paddlex/inference/utils/io/tablepyxl.pystring_to_intr      s     	yy{{1v    c                     [         R                  " U 5      nUR                  S5      nU H  nUR                  5         M     UR                  S5       Vs/ s H  n[	        U5      PM     sn$ s  snf )z 
Find all the tables in the doc
z//comment()z//table)r
   
fromstringxpathdrop_tagr   )doctreecommentscommenttables        r   
get_Tablesr    &   s]    
 ??3Dzz-(H &*jj&;<&;UE%L&;<<<s   A,c           	         SSK Jn  UnUR                   GH  nUR                   GH  nU R	                  X#S9n[        X5      (       a&  US-  nU R	                  X#S9n[        X5      (       a  M&  [        UR                  R                  SS5      5      n	[        UR                  R                  SS5      5      n
U
S:  d  U	S:  a  U R                  UUX*-   S-
  X9-   S-
  S9  UR                  Ul
        UR                  U5        UR                  S	5      nUR                  S
5      nU	S:X  a  [        U R                  [        U5         R                   =(       d    S[#        UR                  5      S-   5      nU(       a  X:  a  UnOU(       a  X:  a  UnXR                  [        U5         l        X9-  nGM     US-  nUnGM     U$ )zq
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_cellr0   r%   r'   	min_width	max_widthr:   s                 r   
write_rowsrC   2   s    .NYY	#//J>>c>9DT..! ~~#~= T.. $J$6$6$:$:9c$JKG#J$6$6$:$:9c$JKG{gk%%!!'MA-%/!3	 &  $))DJd#"00=I"00=I!|
 //0A&0IJPPUTU
(()A- !2%E5#4%EOT++,=f,EFLFG *H 	qM N Jr   c                 n    UR                  U R                  R                  S5      S9n[        XSS5        g)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_sheetr2   r3   insert_table)r   wbwss      r   table_to_sheetrK   e   s/    
 
u}}008	9BAq!r   Nc                     U(       d%  [        5       nUR                  UR                  5        [        XSS9R	                  5       n[        U5      nU H  n[        XQ5        M     U$ )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    rK   )r   rI   rM   inline_styles_doctablesr   s         r   document_to_workbookrT   n   s]     Z
		"))!uik  )*Fu!  Ir   c                 8    [        XS9nUR                  U5        g)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
)rM   N)rT   save)r   filenamerM   rI   s       r   document_to_xlrX      s    
 
c	5BGGHr   c                     U R                   (       a  [        XR                   X25      nU R                  (       a  [        XR                  X25      ngg)zD
Inserts a table into the worksheet at the specified column and row
N)headrC   body)r   r<   r$   r#   s       r   rH   rH      s7     zzJJ<zzJJ< r   c                 b    UR                   nUR                  UR                  pC[        XX45        g)z=
Inserts a table at the location of an openpyxl Cell object.
N)parentr$   r#   rH   )r   r0   rJ   r$   r#   s        r   insert_table_at_cellr^      s&     
B++txxCF(r   )r   )NN)N)
__future__r   
utils.depsr   r   styler   r	   r
   r   r   openpyxl.utilsr   r   r   r   r    rC   rK   rT   rX   rH   r^    r   r   <module>rd      s    ' C FJ!0K  # =  = 
#/ $/d" 
K0 1*=)r   