+
    ˤsj%                         ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIHt	 R t
RR lt^ RIHtHt ^ RIHt ^ RIHt RR ltR	 tR
 t]R8X  d
   ]! 4        R# R# )    N)Imagec                    V P                    F^  p\        P                  ! VP                  P	                  4       4      p\        V4      pVP                  Vn        VP                  V4       K`  	  R# )u?   Copia imágenes de una hoja a otra de manera segura en openpyxlN)_imagesioBytesIOrefgetvalueOpenpyxlImageanchor	add_image)source_sheettarget_sheetimg	img_bytesnew_imgs   &&   'python_scripts/generate_excel_report.pycopy_imagesr   	   sP    ##JJsww//12		*w'	 $    c                .   Vf   RpV P                  ^^dR7       F  pV F  pVP                  '       g   K  \        VP                  \        4      '       g   K9  VP	                  4       VP                  P	                  4       9   g   Kh  V'       d   W%n          R# VP
                  pV P                  P                   F"  pVP                  V9   g   K  VP                  p M	  V P                  VP                  V^,           R7      pW(n          R# 	  K  	  R# )zSReemplaza la celda adyacente a un texto dado, o la celda misma si replace_self=TrueX)min_rowmax_rowT)rowcolumnF)	iter_rowsvalue
isinstancestrlowerr   merged_cellsranges
coordinatemax_colcellr   )	sheetlabelr   replace_selfr   r$   col_idxmerged_rangetargets	   &&&&     r   replace_in_sheetr+      s    }q#6DzzzjS99;;=DJJ$4$4$66#%*
# #'++,1,>,>,E,EL#,>*6*>*> % -F
 "'1!M',#!  7$ r   )OneCellAnchorAnchorMarker)XDRPositiveSize2D)coordinate_to_tuplec                F   \         P                  ! V 4      ;_uu_ 4       pVP                  w  rg\        W,          W',          4      p\	        Wh,          4      p	\	        Wx,          4      p
VP                  W3\         P                  P                  4      pVP                  R8w  d   VP                  R4      p\        ^ W9,
          ^,          ^,           4      p\        ^ WJ,
          ^,          ^,           4      pW,           pW,           p\         P                  ! RW3R4      pVP                  WV34       \        P                  ! 4       pVP                  VRR7       VP!                  ^ 4       \#        V4      pVVn        VVn        VuuRRR4       #   + '       g   i     R# ; i)u   Abre una imagen, la redimensiona a mayor tamaño manteniendo su proporción y le añade padding transparente para desplazarla más a la derecha y abajo dentro de la tabla.RGBAPNG)formatN)r   r   r   r   )PILImageopensizeminintresize
ResamplingLANCZOSmodeconvertmaxnewpaster   r   saveseekr
   widthheight)img_path	max_width
max_heightcontainer_widthcontainer_heightr   rC   rD   ratio	new_width
new_heightimg_resizedpad_leftpad_topcanvas_widthcanvas_heightcanvasimg_byte_arrxl_imgs   &&&&&              r   resize_image_constrainedrU   .   sH   	x	 	 CI%z':;&	(
 jj)!8(:M:M:U:UVv%%--f5K qO7A=CDa+8Q>"DE +", f|&C\R[W"56zz|L/!|,#%A 
!	 	 	 s   E%FF 	c                    V P                  ^^2^^dR7       F'  pV F  pVP                  '       g   K  RVn        K   	  K)  	  R# )zBLimpia todo el contenido a la derecha de la columna M (columna 13))min_colr#   r   r   N)r   r   )r%   r   r$   s   &  r   clear_outside_tablerX   R   s8    r2q#NDzzz!
  Or   c                     \        \        P                  4      ^8  d"   \        R4       \        P                  ! ^4       \        P                  ^,          p \        P                  ^,          p\        P                  ^,          p\        VRRR7      ;_uu_ 4       p\        P                  ! V4      pRRR4       \        P                  ! V 4      pRR.p\        VP                  4       F"  pWv9  g   K  VP                  WW,          4       K$  	  VR,          pVR,          p	^p
. pX EF  pVP                  V4      pRV
 2Vn        VP                  VP                  4       \!        W4       \#        V4       \%        VR	VP'                  R
R4      4       \%        VR\)        VP'                  RR4      4      4       \%        VR\)        V
4      4       \%        VRVP'                  RR4      4       \%        VRVP'                  RR4      4       \%        VRVP'                  RR4      4       \%        VRVP'                  RR4      4       \%        VRVP'                  RR4      4       VP'                  R4      pV'       d   \%        WR4       VP'                  R. 4      p\+        ^\        V4      4      pV^,           ^,          p\-        ^V^,           4       EFE  pV^8X  d   RMRV^,
           2pVP                  V	4      pRV
 V 2Vn        VP                  VP                  4       V	P.                   F  p\1        VP2                  R4      '       d!   VP2                  P4                  P6                  M^ pV^
8  g   KJ  \8        P:                  ! VP<                  P?                  4       4      p\A        V4      pRVn        VPB                  ^8  d<   R VPB                  ,          p^Vn!        \E        VPF                  V,          4      Vn#        VPI                  V4       K  	  \#        V4       V^8X  d   \)        V
4      MV
 RV^,
           2p\%        VR	VP'                  R
R4      4       \%        VR\)        VP'                  RR4      4      4       \%        VRV4       \%        VR!VP'                  RR4      4       \%        VR"VP'                  RR4      4       \%        VR#VP'                  RR4      4       \%        VR$VP'                  RR4      4       \%        VRVP'                  RR4      4       VP'                  R%R&4      '       d   V^8X  d   RVR'&   V^,
          ^,          pV\        V4      8  dG   VV,          p \K        V4      pR(Vn        VPI                  V4       \%        VR)R*V^,            2R+R,7       V^,           \        V4      8  g   EK  VV^,           ,          p \K        V4      p R/V n        VPI                  V 4       \%        VR0R*V^,            2R+R,7       EKH  	  V
^,          p
EK  	  VP                   F"  pW{9  g   K  VP                  WW,          4       K$  	  \        VP                  4      ^ 8  d   ^ Vn'        VPQ                  V4       \        R14       R#   + '       g   i     EL; i  \L         d   p\        R-T R.T 24        Rp?EL!Rp?ii ; i  \L         d   p\        R-T R.T 24        Rp?EK*  Rp?ii ; i)2   zPUsage: python generate_excel_report.py <template.xlsx> <data.json> <output.xlsx>rzutf-8)encodingNz	Anexo (1)zReporte Fotografico (1)zAnexo zEntidad Fiscalizada:entidad_fiscalizadar   zCuenta pcuenta_publicazAnexo :z	CONTRATO:numero_contratozMONTO DE CONTRATO:inversion_autorizadau   DESCRIPCIÓN:nombre_obrazMONTO EJERCIDO:inversion_ejercidazCONTRATISTA:contratistaestado_obrafotos .zReporte Fotografico _fromA1g     @j@zOBRA:zNo. CONTRATO:zIMPORTE CONTRATADO:zIMPORTE EJERCIDO:tipo_plantilla_sin_fotosFD31B17zFoto:1zFoto:T)r'   zError cargando foto z: B40zFoto:2Success))lensysargvprintexitr5   jsonloadopenpyxlload_workbooklist
sheetnamesremovecopy_worksheettitleappendr   rX   r+   getr   r>   ranger   hasattrr   rh   r   r   r   r   r	   r
   rC   r8   rD   r   rU   	ExceptionactiverA   )!template_path	json_pathoutput_pathfdatawb
base_names
sheet_namesheet_anexosheet_reporte
obra_indexgenerated_sheet_namesmuestratarget_anexoestadore   fotos_countphoto_pagespsuffixtarget_reporter   r   r   r   rJ   	anexo_numoffset
foto1_pathxl_img1e
foto2_pathxl_img2s!                                    r   mainr   Y   s   
388}q`aHHQKMI((1+K	iw	/	/1yy| 
0 
			.B 89J 2==)
'IIbn% * [/K01MJ((5%j\2$$\%7%78K.L)'=w{{K`be?fgz3w{{CSUX7Y3Z[y#j/B{GKK@QSV4WX';W[[I_ad=efMSV8WX'8'++FZ\_:`a~w{{=RU7VW]+\37 GR(!SZ("Q1,q+/*A6R1Q3%yF..}=N%9*fX#NN !(()=)=> %,,.5cjj'.J.Jcjj&&**PQ8 "

377+;+;+= >I+I6G%)GN}}s* % 5(+),W^^e-C)D",,W5 -  /+,6J*Qqse7LI^-CW[[QfhkElm^ZW[[IY[^=_9`a^Y	B^Wgkk-QT6UV^_gkkJ[]`>ab^-BGKKPfhkDlm^-@'++NbdgBhi^^W[[X[=\] {{5u==!q&(+u% !eq[F E
""6]
D6zBG%*GN",,W5$^Xvaxj?Q`de
 zCJ&"6A:.
D6zBG%*GN",,W5$^Xvaxj?Q`dees +z 	a
o v mm
2IIbn% $
 2==A	GGK	)s 
0	/	/| ! D0BqcBCCD ! D0BqcBCCDs<   Z2<Z-<[Z*	-[8[[[?"[::[?__main__)F)i  i6  i  iT  )rp   rt   rv   r   copyopenpyxl.drawing.imager   r
   PILr4   r   r+   $openpyxl.drawing.spreadsheet_drawingr,   r-   openpyxl.drawing.xdrr.   openpyxl.utils.cellr/   rU   rX   r   __name__ r   r   <module>r      sV    
   	  9 !(2 M 2 3"H"BH zF r   