o
    ðäjÚ"  ã                   @   sz  d Z dZddlmZ ddlZddlZddlmZ ddlm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mZ ddlmZ ejejejejfZejejejejejejejejiZe e!efZ"ee e" e#e$dƒf Z%e &d¡Z'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0e)e*e+e,e-e.e/e0fZ1e2de3de de#diZ4dd„ Z5dd„ Z6G dd„ deƒZ7G dd„ deƒZ8d dd„Z9dS )!züManage individual cells in a spreadsheet.

The Cell class is required to know its value and type, display options,
and any other features of an Excel cell.  Utilities for referencing
cells using Excel's 'A1' column/row nomenclature are also provided.

zrestructuredtext ené    )ÚcopyN)ÚNUMERIC_TYPES)ÚIllegalCharacterError)Úget_column_letter)ÚnumbersÚis_date_format)ÚStyleableObject)Ú	Hyperlink)ÚDataTableFormulaÚArrayFormula)ÚCellRichTextz#[\000-\010]|[\013-\014]|[\016-\037])z#NULL!z#DIV/0!z#VALUE!z#REF!z#NAME?z#NUM!ú#N/AÚsÚfÚnÚbÚ	inlineStrÚeÚstrc                 C   sT   t |tƒrd}nt |tƒrd}nt |tƒrd}nt |ttfƒr"d}nd S |t| < |S )Nr   r   Údr   )Ú
isinstancer   ÚSTRING_TYPESÚ
TIME_TYPESr
   r   Ú_TYPES)ÚtÚvalueÚdt© r   úV/var/www/ticemtrilhas/avaliacao_env/lib/python3.10/site-packages/openpyxl/cell/cell.pyÚget_typeA   s   


r   c                 C   sT   t  | ¡}|r	|S |  ¡ dd … D ]}t  |¡}|r"|t | < |  S qtd |¡ƒ‚)Né   z#Could not get time format for {0!r})ÚTIME_FORMATSÚgetÚmroÚ
ValueErrorÚformat)r   r   Úbaser   r   r   Úget_time_formatP   s   

þr'   c                       sò   e Zd ZdZdZd(‡ fdd„	Zedd„ ƒZedd	„ ƒZed
d„ ƒZ	edd„ ƒZ
edd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zedd„ ƒZejdd„ ƒZedd„ ƒZedd„ ƒZejdd„ ƒZed d!„ ƒZd)d#d$„Zed%d&„ ƒZejd'd&„ ƒZ‡  ZS )*ÚCellzpDescribes cell associated properties.

    Properties of interest include style, type, value, and address.

    )ÚrowÚcolumnÚ_valueÚ	data_typeÚparentÚ
_hyperlinkÚ_commentNc                    sH   t ƒ  ||¡ || _	 || _	 d | _d | _d| _|d ur|| _d | _d S )Nr   )	ÚsuperÚ__init__r)   r*   r+   r.   r,   r   r/   )ÚselfÚ	worksheetr)   r*   r   Ústyle_array©Ú	__class__r   r   r1   l   s   
zCell.__init__c                 C   s   t | jƒ}|› | j› �S )z!This cell's coordinate (ex. 'A5'))r   r*   r)   )r2   Úcolr   r   r   Ú
coordinate{   s   
zCell.coordinatec                 C   ó   | j S )z!The numerical index of the column)r*   ©r2   r   r   r   Úcol_idx‚   ó   zCell.col_idxc                 C   s
   t | jƒS ©N)r   r*   r:   r   r   r   Úcolumn_letterˆ   ó   
zCell.column_letterc                 C   s   | j jS r=   )r-   Úencodingr:   r   r   r   r@   �   s   zCell.encodingc                 C   s
   | j j jS r=   )r-   Úepochr:   r   r   r   Ú	base_date‘   r?   zCell.base_datec                 C   ó   d  | jj| j¡S )Nz<Cell {0!r}.{1}>©r%   r-   Útitler8   r:   r   r   r   Ú__repr__–   ó   zCell.__repr__c                 C   sX   |du rdS t |tƒst|| jƒ}t|ƒ}|dd… }tt |¡dƒr*t|› d�ƒ‚|S )z5Check string coding, length, and line break characterNiÿ  z cannot be used in worksheets.)r   r   r@   ÚnextÚILLEGAL_CHARACTERS_REÚfinditerr   ©r2   r   r   r   r   Úcheck_string™   s   
zCell.check_stringc                 C   s    zt |ƒW S  ty   Y dS w )z Tries to convert Error" else N/Ar   )r   ÚUnicodeDecodeErrorrK   r   r   r   Úcheck_error¨   s
   
ÿzCell.check_errorc                 C   sÐ   d| _ t|ƒ}zt| }W n ty   t||ƒ}Y nw |du r+|dur+td |¡ƒ‚|r0|| _ |dkr?t| jƒs>t	|ƒ| _n$|dkrct
|tƒsc|  |¡}t|ƒdkr\| d¡r\d| _ n|tv rcd	| _ || _dS )
z*Given a value, infer the correct data typer   NzCannot convert {0!r} to Excelr   r   r    ú=r   r   )r,   Útyper   ÚKeyErrorr   r$   r%   r   Únumber_formatr'   r   r   rL   ÚlenÚ
startswithÚERROR_CODESr+   )r2   r   r   r   r   r   r   Ú_bind_value°   s,   ÿ

€

zCell._bind_valuec                 C   r9   )z“Get or set the value held in the cell.

        :type: depends on the value (string, float, int or
            :class:`datetime.datetime`)
        ©r+   r:   r   r   r   r   Î   s   z
Cell.valuec                 C   s   |   |¡ dS )z1Set the value and infer type and display options.N)rV   rK   r   r   r   r   ×   s   c                 C   r9   )z#Always returns the value for excel.rW   r:   r   r   r   Úinternal_valueÜ   r<   zCell.internal_valuec                 C   r9   )z.Return the hyperlink target or an empty string)r.   r:   r   r   r   Ú	hyperlinká   r<   zCell.hyperlinkc                 C   sV   |du r	d| _ dS t|tƒstd|d�}| j|_|| _ | jdu r)|jp%|j| _dS dS )a  Set value and display for hyperlinks in a cell.
        Automatically sets the `value` of the cell with link text,
        but you can modify it afterwards by setting the `value`
        property, and the hyperlink will remain.
        Hyperlink is removed if set to ``None``.NÚ )ÚrefÚtarget)	r.   r   r	   r8   r[   r+   r\   Úlocationr   )r2   Úvalr   r   r   rY   ç   s   


ÿc                 C   s   | j dkp| j dkot| jƒS )zFTrue if the value is formatted as a date

        :type: bool
        r   r   )r,   r   rR   r:   r   r   r   Úis_dateù   s   
ÿzCell.is_dater   c                 C   s$   | j | }| j| }| jj||d�S )z÷Returns a cell location relative to this cell.

        :param row: number of rows to offset
        :type row: int

        :param column: number of columns to offset
        :type column: int

        :rtype: :class:`openpyxl.cell.Cell`
        )r*   r)   )r;   r)   r-   Úcell)r2   r)   r*   Úoffset_columnÚ
offset_rowr   r   r   Úoffset  s   

zCell.offsetc                 C   r9   )zn Returns the comment associated with this cell

            :type: :class:`openpyxl.comments.Comment`
        )r/   r:   r   r   r   Úcomment  s   zCell.commentc                 C   sD   |dur|j rt|ƒ}| | ¡ n|du r| jr| j ¡  || _dS )z,
        Assign a comment to a cell
        N)r-   r   Úbindr/   ÚunbindrK   r   r   r   rd     s   

)NNNN)r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r1   Úpropertyr8   r;   r>   r@   rB   rF   rL   rN   rV   r   ÚsetterrX   rY   r_   rc   rd   Ú__classcell__r   r   r5   r   r(   \   sF    














r(   c                       sL   e Zd ZdZdZdZdZdZdZd	‡ fdd„	Z	dd„ Z
ejZeZeZ‡  ZS )
Ú
MergedCellz¥
    Describes the properties of a cell in a merged cell and helps to
    display the borders of the merged cell.

    The value of a MergedCell is always None.
    )r)   r*   Nr   c                    s   t ƒ  |¡ || _|| _d S r=   )r0   r1   r)   r*   )r2   r3   r)   r*   r5   r   r   r1   =  s   
zMergedCell.__init__c                 C   rC   )Nz<MergedCell {0!r}.{1}>rD   r:   r   r   r   rF   C  rG   zMergedCell.__repr__©NN)rg   rh   ri   rj   rk   r+   r,   rd   rY   r1   rF   r(   r8   r/   r   rn   r   r   r5   r   ro   ,  s    ro   c                 C   s   t | dd|d�S )Nr    )r3   r*   r)   r   )r(   )Úwsr   r   r   r   ÚWriteOnlyCellK  s   rr   rp   ):rj   Ú__docformat__r   ÚdatetimeÚreÚopenpyxl.compatr   Úopenpyxl.utils.exceptionsr   Úopenpyxl.utilsr   Úopenpyxl.stylesr   r   Úopenpyxl.styles.styleabler   Úopenpyxl.worksheet.hyperlinkr	   Úopenpyxl.worksheet.formular
   r   Úopenpyxl.cell.rich_textr   ÚdateÚtimeÚ	timedeltar   ÚFORMAT_DATE_DATETIMEÚFORMAT_DATE_YYYYMMDD2ÚFORMAT_DATE_TIME6ÚFORMAT_DATE_TIMEDELTAr!   r   Úbytesr   ÚboolrP   ÚKNOWN_TYPESÚcompilerI   rU   ÚTYPE_STRINGÚTYPE_FORMULAÚTYPE_NUMERICÚ	TYPE_BOOLÚ	TYPE_NULLÚTYPE_INLINEÚ
TYPE_ERRORÚTYPE_FORMULA_CACHE_STRINGÚVALID_TYPESÚintÚfloatr   r   r'   r(   ro   rr   r   r   r   r   Ú<module>   sR   ü

ÿ Q