o
    g                     @   s|   d dl Z d dlmZ d dlmZmZ d dlmZ d dlm	Z	 ddl
mZ G dd	 d	eZG d
d deZG dd deZdS )    N)Serialisable)IntegerSequence)
MergedCell)Border   )	CellRangec                       s6   e Zd ZdZejZdZ	d fdd	Zdd Z	  Z
S )		MergeCell	mergeCell)refNc                    s   t  | d S N)super__init__)selfr   	__class__ R/var/www/html/api-tag/env/lib/python3.10/site-packages/openpyxl/worksheet/merge.pyr      s   zMergeCell.__init__c                 C   s   |  | jS r   )r   r   r   r   r   r   __copy__   s   zMergeCell.__copy__r   )__name__
__module____qualname__tagnamer   coordr   	__attrs__r   r   __classcell__r   r   r   r   r	      s    r	   c                   @   sF   e Zd ZdZeddZeedZdZ	dZ
		dd	d
Zedd ZdS )
MergeCells
mergeCellsT)
allow_none)expected_typer
   )countNr   c                 C   s
   || _ d S r   r!   )r   r"   r
   r   r   r   r   -   s   
zMergeCells.__init__c                 C   s
   t | jS r   )lenr
   r   r   r   r   r"   4   s   
zMergeCells.count)Nr   )r   r   r   r   r   r"   r   r	   r
   __elements__r   r   propertyr   r   r   r   r   #   s    


r   c                       s@   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Z  Z	S )MergedCellRangea   
    MergedCellRange stores the border information of a merged cell in the top
    left cell of the merged cell.
    The remaining cells in the merged cell are stored as MergedCell objects and
    get their border information from the upper left cell.
    c                    s&   || _ t j|d d | _|   d S )N)range_string)wsr   r   
start_cell_get_borders)r   	worksheetr   r   r   r   r   B   s   zMergedCellRange.__init__c                 C   s~   | j j| j| jf| _| jdu r| j j| j| jd| _| j j| j| jf}|dur=| j j	t
|j	j|j	jd7  _	dS dS )a  
        If the upper left cell of the merged cell does not yet exist, it is
        created.
        The upper left cell gets the border information of the bottom and right
        border from the bottom right cell of the merged cell, if available.
        Nrowcolumn)rightbottom)r(   _cellsgetmin_rowmin_colr)   cellmax_rowmax_colborderr   r/   r0   )r   end_cellr   r   r   r*   I   s   	
zMergedCellRange._get_bordersc                 C   s  g d}|D ]J}t | jj|}|r|jdu rqtdi ||i}t | |D ]*}| jj|}|du rH|\}}t| j||d}|| jj|j	|j
f< | j|7  _q%q| jjdu}	|	r`t| jj}
| jD ](}| jj|}|du r|\}}t| j||d}|| jj|j	|j
f< |	r|
|_qcdS )a  
        Each cell of the merged cell is created as MergedCell if it does not
        already exist.

        The MergedCells at the edge of the merged cell gets its borders from
        the upper left cell.

         - The top MergedCells get the top border from the top left cell.
         - The bottom MergedCells get the bottom border from the top left cell.
         - The left MergedCells get the left border from the top left cell.
         - The right MergedCells get the right border from the top left cell.
        )topleftr/   r0   Nr,   r   )getattrr)   r8   styler   r(   r1   r2   r   r-   r.   
protectioncopycells)r   namesnamesider8   r   r5   r-   col	protectedr>   r   r   r   format]   s6   
zMergedCellRange.formatc                 C   s   |t | jv S r   )r   r   )r   r   r   r   r   __contains__   s   zMergedCellRange.__contains__c                 C   s   |  | j| jS r   )r   r(   r   r   r   r   r   r      s   zMergedCellRange.__copy__)
r   r   r   __doc__r   r*   rF   rG   r   r   r   r   r   r   r&   9   s    +r&   )r?   !openpyxl.descriptors.serialisabler   openpyxl.descriptorsr   r   openpyxl.cell.cellr   openpyxl.styles.bordersr   
cell_ranger   r	   r   r&   r   r   r   r   <module>   s   