o
    ®2ŒZèq  ã                   @   sÆ  d dl mZ 	 d dlmZmZ d dlmZ d dlZd dlm	Z	 d dl
mZ d dlmZmZmZmZmZ d dlmZmZmZmZmZ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"m#Z#m$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l0m1Z1 ddl2m3Z3m4Z4m5Z5 ddl6m7Z7m8Z8m9Z9m:Z: ddl;m<Z< ddl=m>Z>m?Z? ddl@mAZAmBZBmCZCmDZD ddlEmFZFmGZG ddlHmIZI ddlJmKZK edƒdd„ ƒZLG dd „ d e*ƒZMd!d"„ ZNdS )#é    )Úabsolute_import)ÚisliceÚproduct)Ú
attrgetterN)Úisgenerator)Úwarn)ÚunicodeÚrangeÚ
basestringÚ
deprecatedÚsafe_string)Úcoordinate_from_stringÚcolumn_index_from_stringÚget_column_letterÚrange_boundariesÚrows_from_rangeÚcoordinate_to_tupleÚabsolute_coordinate)ÚCOORD_RE)ÚCell)ÚSheetTitleExceptionÚNamedRangeException)Úpoints_to_pixelsÚDEFAULT_COLUMN_WIDTHÚDEFAULT_ROW_HEIGHT)ÚConditionalFormattingList)ÚRelationshipList)Ú_WorkbookChild)ÚCOL_RANGE_REÚROW_RANGE_RE)ÚBoundDictionaryé   )ÚDataValidationList)ÚPrintPageSetupÚPageMarginsÚPrintOptions)ÚColumnDimensionÚRowDimensionÚDimensionHolderÚSheetFormatProperties)ÚSheetProtection)Ú
AutoFilterÚ	SortState)Ú	SheetViewÚPaneÚ	SelectionÚSheetViewList)ÚMultiCellRangeÚ	CellRange)ÚWorksheetProperties)Ú	PageBreakz!Use the worksheet.values propertyc                 c   s    � | D ]
}dd„ |D ƒV  qdS )zReturn cell values row-by-rowc                 s   ó   � | ]}|j V  qd S ©N©Úvalue©Ú.0Úc© r<   úN/var/www/html/env/lib/python3.10/site-packages/openpyxl/worksheet/worksheet.pyÚ	<genexpr>Q   ó   € zflatten.<locals>.<genexpr>Nr<   )ÚresultsÚrowr<   r<   r=   ÚflattenL   s   €ÿrB   c                   @   s  e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZd—dd„Zdd„ Zedd„ ƒZedd „ ƒZed!d"„ ƒZed#d$„ ƒZ 	 ed%d&„ ƒZ!ed'd(„ ƒZ"ed)d*„ ƒZ#e#j$d+d*„ ƒZ#	 e%d,ƒd-d.„ ƒZ&ed/d0„ ƒZ'e'j$d—d1d0„ƒZ'e%d2ƒd˜d4d5„ƒZ(d—d6d7„Z)d8d9„ Z*d:d;„ Z+d<d=„ Z,d>d?„ Z-d@dA„ Z.dBdC„ Z/edDdE„ ƒZ0edFdG„ ƒZ1edHdI„ ƒZ2edJdK„ ƒZ3dLdM„ Z4edNdO„ ƒZ5		d™dPdQ„Z6dRdS„ Z7edTdU„ ƒZ8edVdW„ ƒZ9dšdXdY„Z:dZd[„ Z;ed\d]„ ƒZ<e%d^ƒd_d`„ ƒZ=e%daƒdbdc„ ƒZ>ddde„ Z?dfdg„ Z@d—dhdi„ZAd—djdk„ZBdldm„ ZCdndo„ ZDd›dpdq„ZEee%drƒdsdt„ ƒƒZFd›dudv„ZGdwdx„ ZHdœdzd{„ZId�d|d}„ZJd�d~d„ZKd�d€d�„ZLd�d‚dƒ„ZMd„d…„ ZNd†d‡„ ZOdˆd‰„ ZPdŠd‹„ ZQedŒd�„ ƒZReRj$dŽd�„ ƒZRed�d�„ ƒZSeSj$d‘d�„ ƒZSed’d“„ ƒZTed”d•„ ƒZUeUj$d–d•„ ƒZUdS )žÚ	Worksheetz…Represents a worksheet.

    Do not create worksheets yourself,
    use :func:`openpyxl.workbook.Workbook.create_sheet` instead

    Ú	worksheetz/xl/worksheets/sheet{0}.xmlzIapplication/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xmlr   r!   é   ÚvisibleÚhiddenÚ
veryHiddenÚ1Ú2Ú3Ú4Ú5Ú6Ú7Ú8Ú9Ú10Ú11ÚportraitÚ	landscapeNc                 C   s   t  | ||¡ |  ¡  d S r6   )r   Ú__init__Ú_setup)ÚselfÚparentÚtitler<   r<   r=   rV   y   s   zWorksheet.__init__c                 C   sü   t d| jƒ| _t| | jd�| _tƒ | _i | _g | _	g | _
tƒ | _d | _g | _tƒ | _g | _g | _tƒ | _g | _d| _t| d�| _tƒ | _d | _d | _d | _tƒ | _t ƒ | _!t"ƒ | _#d| _$t%ƒ | _&t'ƒ | _(d | _)i | _*d | _+t,ƒ | _-d | _.t/ƒ | _0t1ƒ | _2d S )NÚindex)rD   Údefault_factoryrF   )rD   r   )3r    Ú_add_rowÚrow_dimensionsr(   Ú_add_columnÚcolumn_dimensionsr4   Úpage_breaksÚ_cellsÚ_chartsÚ_imagesr   Ú_relsÚ_drawingÚ	_commentsr1   Úmerged_cellsÚ_tablesÚ_pivotsr"   Údata_validationsÚ_hyperlinksÚsheet_stater#   Ú
page_setupr%   Úprint_optionsÚ_print_rowsÚ_print_colsÚ_print_arear$   Úpage_marginsr0   Úviewsr*   Ú
protectionÚ_current_rowr+   Úauto_filterr,   Ú
sort_stateÚ
paper_sizeÚformula_attributesÚorientationr   Úconditional_formattingÚlegacy_drawingr3   Úsheet_propertiesr)   Úsheet_format©rX   r<   r<   r=   rW   }   sF   ÿzWorksheet._setupc                 C   s   | j jd S )Nr   )rt   Ú	sheetViewr€   r<   r<   r=   Ú
sheet_view£   s   zWorksheet.sheet_viewc                 C   ó
   | j jjS r6   )r‚   Ú	selectionÚsqrefr€   r<   r<   r=   Úselected_cell¨   ó   
zWorksheet.selected_cellc                 C   rƒ   r6   )r‚   r„   Ú
activeCellr€   r<   r<   r=   Úactive_cell­   r‡   zWorksheet.active_cellc                 C   s   | j jS r6   )r‚   ÚshowGridLinesr€   r<   r<   r=   Úshow_gridlines±   s   zWorksheet.show_gridlinesc                 C   rƒ   r6   )r~   Ú	outlinePrÚsummaryBelowr€   r<   r<   r=   Úshow_summary_below·   r‡   zWorksheet.show_summary_belowc                 C   rƒ   r6   )r~   rŒ   ÚsummaryRightr€   r<   r<   r=   Úshow_summary_right»   r‡   zWorksheet.show_summary_rightc                 c   s2   � dD ]}t | j|ƒ}|d ur|t|ƒfV  qd S ©N)	ÚcodeNameÚ!enableFormatConditionsCalculationÚ
filterModeÚ	publishedÚsyncHorizontalÚsyncRefÚsyncVerticalÚtransitionEvaluationÚtransitionEntry)Úgetattrr~   r   )rX   Úattrr8   r<   r<   r=   Úvba_code¿   s   €€ûzWorksheet.vba_codec                 C   s,   |  ¡ D ]\}}|dv rt| j||ƒ qd S r‘   )ÚitemsÚsetattrr~   )rX   r8   ÚkÚvr<   r<   r=   r�   È   s
   €üzUse the ws.values propertyc                 C   s
   | j  ¡ S )z8Return an unordered list of the cells in this worksheet.)rb   Úvaluesr€   r<   r<   r=   Úget_cell_collectionÓ   s   
zWorksheet.get_cell_collectionc                 C   s   | j jd ur| j jjS d S r6   )r‚   ÚpaneÚtopLeftCellr€   r<   r<   r=   Úfreeze_panesÙ   s   
ÿzWorksheet.freeze_panesc                 C   s
  t |tƒr|j}|dkrd }|sd | j_d S t|ƒ\}}| j}t|ddd�|_d|jd _|dkr7|d |j_|dkrY|d |j_	d|j_
d|jd _|dkrYd|jd _d|j_
|dkr�|dkrƒt|jƒ}| dtdd d d	�¡ | dtdd d d	�¡ ||_d S d S d S )
NÚA1ÚtopRightÚfrozen)r¥   Ú
activePaneÚstater   r!   Ú
bottomLeftÚbottomRight)r¤   rˆ   r…   )Ú
isinstancer   Ú
coordinater‚   r¤   r   r.   r„   ÚxSplitÚySplitrª   ÚlistÚinsertr/   )rX   r¥   rA   ÚcolumnÚviewÚselr<   r<   r=   r¦   Þ   s:   
þ

üz)Set print titles rows or columns directlyÚrowsc                 C   s4   | j  | ¡}|dkrdt|ƒ | _dS d| | _dS )z— Print Titles are rows or columns that are repeated on each printed sheet.
        This adds n rows or columns at the top or left of the sheet
        ÚcolszA:%sz1:%dN)rY   Ú	get_indexr   Úprint_title_colsÚprint_title_rows)rX   ÚnÚrows_or_colsÚscoper<   r<   r=   Úadd_print_title  s   zWorksheet.add_print_titlec                 C   s6   |dk s|dk rt dƒ‚|  ||¡}|dur||_|S )a  
        Returns a cell object based on the given coordinates.

        Usage: cell(row=15, column=1, value=5)

        Calling `cell` creates cells in memory when they
        are first accessed.

        :param row: row index of the cell (e.g. 4)
        :type row: int

        :param column: column index of the cell (e.g. 3)
        :type column: int

        :param value: value of the cell (e.g. 5)
        :type value: numeric or time or string or bool or none

        :rtype: openpyxl.cell.cell.Cell
        r!   z'Row or column values must be at least 1N)Ú
ValueErrorÚ	_get_cellr8   )rX   rA   r´   r8   Úcellr<   r<   r=   rÂ     s   zWorksheet.cellc                 C   s4   ||f}|| j vrt| ||d�}|  |¡ | j | S )zƒ
        Internal method for getting a cell from a worksheet.
        Will create a new cell if one doesn't already exist.
        )rA   Úcol_idx)rb   r   Ú	_add_cell)rX   rA   r´   r¯   rÂ   r<   r<   r=   rÁ   0  s
   


zWorksheet._get_cellc                 C   s,   |j }|j}t|| jƒ| _|| j||f< dS )z:
        Internal method for adding cell objects.
        N)rÃ   rA   Úmaxrv   rb   )rX   rÂ   r´   rA   r<   r<   r=   rÄ   <  s   zWorksheet._add_cellc                 C   sú   t |tƒrt|j|jgƒstd |¡ƒ‚d |j|j¡}t |tƒr%t|ƒ}t	|ƒ\}}}}t
||||gƒs<td |¡ƒ‚|sPt|  ||¡ƒ}||krN|d }|S |sht| j||| j|d�ƒ}||krf|d }|S d|vrr|  ||¡S t| j||||d�ƒS )al  Convenience access by Excel style coordinates

        The key can be a single cell coordinate 'A1', a range of cells 'A1:D25',
        individual rows or columns 'A', 4 or ranges of rows or columns 'A:D',
        4:10.

        Single cells will always be created if they do not exist.

        Returns either a single cell or a tuple of rows or columns.
        z&{0} is not a valid coordinate or rangez{0}:{1}r   )Úmin_colÚmin_rowÚmax_colÚmax_rowú:)rÇ   rÆ   rÉ   rÈ   )r®   ÚsliceÚallÚstartÚstopÚ
IndexErrorÚformatÚintÚstrr   ÚanyÚtupleÚ	iter_colsÚ	iter_rowsÚ
max_columnrÁ   )rX   ÚkeyrÆ   rÇ   rÈ   rÉ   r¸   r·   r<   r<   r=   Ú__getitem__F  s4   


ÿ
ÿzWorksheet.__getitem__c                 C   s   || | _ d S r6   r7   )rX   rØ   r8   r<   r<   r=   Ú__setitem__o  s   zWorksheet.__setitem__c                 C   ó   |   ¡ S r6   ©rÖ   r€   r<   r<   r=   Ú__iter__s  s   zWorksheet.__iter__c                 C   s.   t |ƒ\}}||f| jv r| j||f= d S d S r6   )r   rb   )rX   rØ   rA   r´   r<   r<   r=   Ú__delitem__w  s   ÿzWorksheet.__delitem__c                 C   ó*   d}| j rtdd„ | j D ƒƒ}t|ƒ}|S )zMThe minimium row index containing data (1-based)

        :type: int
        r!   c                 s   ó   � | ]}|d  V  qdS ©r   Nr<   r9   r<   r<   r=   r>   …  ó   € z$Worksheet.min_row.<locals>.<genexpr>©rb   ÚsetÚmin)rX   rÇ   r·   r<   r<   r=   rÇ   }  ó
   zWorksheet.min_rowc                 C   rß   )zLThe maximum row index containing data (1-based)

        :type: int
        r!   c                 s   rà   rá   r<   r9   r<   r<   r=   r>   ’  râ   z$Worksheet.max_row.<locals>.<genexpr>©rb   rä   rÅ   )rX   rÉ   r·   r<   r<   r=   rÉ   Š  ræ   zWorksheet.max_rowc                 C   rß   )zOThe minimum column index containing data (1-based)

        :type: int
        r!   c                 s   rà   ©r!   Nr<   r9   r<   r<   r=   r>   Ÿ  râ   z'Worksheet.min_column.<locals>.<genexpr>rã   )rX   rÆ   r¸   r<   r<   r=   Ú
min_column—  ræ   zWorksheet.min_columnc                 C   rß   )zOThe maximum column index containing data (1-based)

        :type: int
        r!   c                 s   rà   rè   r<   r9   r<   r<   r=   r>   ¬  râ   z'Worksheet.max_column.<locals>.<genexpr>rç   )rX   rÈ   r¸   r<   r<   r=   r×   ¤  ræ   zWorksheet.max_columnc           	      C   st   | j r,tƒ }tƒ }| j D ]\}}| |¡ | |¡ qt|ƒ}t|ƒ}t|ƒ}t|ƒ}ndS dt|ƒ|t|ƒ|f S )zoReturn the minimum bounding range for all cells containing data (ex. 'A1:M24')

        :rtype: string
        zA1:A1z	%s%d:%s%d)rb   rä   ÚaddrÅ   rå   r   )	rX   r·   r¸   rA   ÚcolrÉ   rÈ   rÆ   rÇ   r<   r<   r=   Úcalculate_dimension±  s   

þzWorksheet.calculate_dimensionc                 C   rÛ   )z1Returns the result of :func:`calculate_dimension`)rì   r€   r<   r<   r=   Ú
dimensionsÉ  ó   zWorksheet.dimensionsc                 C   sž   |durt dƒ t| ¡ ƒ\}}}}| jdkr!t||||gƒs!dS |p$d}|p(d}|p-| j}|p2| j}|dur;||7 }|durC||7 }|  || || ||¡S )a·  
        Produces cells from the worksheet, by row. Specify the iteration range
        using indices of rows and columns.

        If no indices are specified the range starts at A1.

        If no cells are in the worksheet an empty tuple will be returned.

        :param range_string: range string (e.g. 'A1:B2') *deprecated*
        :type range_string: string

        :param min_col: smallest column index (1-based index)
        :type min_col: int

        :param min_row: smallest row index (1-based index)
        :type min_row: int

        :param max_col: largest column index (1-based index)
        :type max_col: int

        :param max_row: smallest row index (1-based index)
        :type max_row: int

        :param row_offset: added to min_row and max_row (e.g. 4)
        :type row_offset: int

        :param column_offset: added to min_col and max_col (e.g. 3)
        :type column_offset: int

        :rtype: generator
        NzGUsing a range string with iter_rows is deprecated. Use ws[range_string]r   r<   r!   )r   r   Úupperrv   rÓ   r×   rÉ   Ú_cells_by_row)rX   Úrange_stringrÇ   rÉ   rÆ   rÈ   Ú
row_offsetÚcolumn_offsetr<   r<   r=   rÖ   Ï  s$   "


ýzWorksheet.iter_rowsc                 #   s>   � t ||d ƒD ]‰ t‡ ‡fdd„t ||d ƒD ƒƒV  qd S )Nr!   c                 3   s   � | ]
}ˆj ˆ |d �V  qdS ©)rA   r´   N©rÂ   )r:   r´   ©rA   rX   r<   r=   r>   	  ó   € ÿz*Worksheet._cells_by_row.<locals>.<genexpr>©r	   rÔ   ©rX   rÆ   rÇ   rÈ   rÉ   r<   rö   r=   rð     s   €ÿÿzWorksheet._cells_by_rowc                 C   rÛ   )zfProduces all cells in the worksheet, by row (see :func:`iter_rows`)

        :type: generator
        rÜ   r€   r<   r<   r=   r·     s   zWorksheet.rowsc                 c   s(   � |   ¡ D ]}tdd„ |D ƒƒV  qdS )zTProduces all cell values in the worksheet, by row

        :type: generator
        c                 s   r5   r6   r7   r9   r<   r<   r=   r>     r?   z#Worksheet.values.<locals>.<genexpr>N)rÖ   rÔ   )rX   rA   r<   r<   r=   r¢     s   €ÿzWorksheet.valuesc                 C   sR   | j dkrt||||gƒsdS |pd}|pd}|p| j}|p | j}|  ||||¡S )aŠ  
        Produces cells from the worksheet, by column. Specify the iteration range
        using indices of rows and columns.

        If no indices are specified the range starts at A1.

        If no cells are in the worksheet an empty tuple will be returned.

        :param min_col: smallest column index (1-based index)
        :type min_col: int

        :param min_row: smallest row index (1-based index)
        :type min_row: int

        :param max_col: largest column index (1-based index)
        :type max_col: int

        :param max_row: smallest row index (1-based index)
        :type max_row: int

        :rtype: generator
        r   r<   r!   )rv   rÓ   r×   rÉ   Ú_cells_by_col)rX   rÆ   rÈ   rÇ   rÉ   r<   r<   r=   rÕ      s   

ÿzWorksheet.iter_colsc                 #   s>   � t ||d ƒD ]‰ t‡ ‡fdd„t ||d ƒD ƒƒV  qdS )z%
        Get cells by column
        r!   c                 3   s   � | ]
}ˆj |ˆ d �V  qdS rô   rõ   )r:   rA   ©r´   rX   r<   r=   r>   J  r÷   z*Worksheet._cells_by_col.<locals>.<genexpr>Nrø   rù   r<   rû   r=   rú   E  s   €ÿÿzWorksheet._cells_by_colc                 C   rÛ   )zGProduces all cells in the worksheet, by column  (see :func:`iter_cols`))rÕ   r€   r<   r<   r=   ÚcolumnsN  rî   zWorksheet.columnszg
    Use ws.iter_rows() or ws.iter_cols() depending whether you
    want rows or columns returned.
    c                 C   s   |   ||||¡S )aï  Returns a 2D array of cells. Will create any cells within the
        boundaries that do not already exist

        :param min_col: smallest column index (1-based index)
        :type min_col: int

        :param min_row: smallest row index (1-based index)
        :type min_row: int

        :param max_col: largest column index (1-based index)
        :type max_col: int

        :param max_row: smallest row index (1-based index)
        :type max_row: int

        :rtype: generator
        )rð   rù   r<   r<   r=   Úget_squared_rangeT  s   zWorksheet.get_squared_rangez=Ranges are workbook objects. Use wb.defined_names[range_name]c           
      C   s¶   | j j| }|jr|j| j  | ¡krd |¡}t|ƒ‚|jdkr)d |¡}t|ƒ‚g }|jD ](\}}| j | }|| kr?t	dƒ‚|| }t
|tƒrL|fg}|D ]}	| |	¡ qNq.t|ƒS )zÛ
        Returns a 2D array of cells, with optional row and column offsets.

        :param range_name: `named range` name
        :type range_name: string

        :rtype: tuple[tuple[openpyxl.cell.cell.Cell]]
        z#{0} not available in this worksheetÚRANGEz"{0} refers to a value, not a rangez+Range includes cells from another worksheet)rY   Údefined_namesÚlocalSheetIdr¹   rÐ   ÚKeyErrorÚtypeÚ	NameErrorÚdestinationsr   r®   r   ÚextendrÔ   )
rX   Ú
range_nameÚdefnÚmsgÚresultrZ   Úcells_rangeÚwsr·   rA   r<   r<   r=   Úget_named_rangen  s&   





ÿzWorksheet.get_named_rangec                 C   s8   || j _|| j| jfvrtd| j| jf ƒ‚|| j _dS )zSet printer settings zValues should be %s or %sN)rn   Ú	paperSizeÚORIENTATION_PORTRAITÚORIENTATION_LANDSCAPErÀ   r{   )rX   ry   r{   r<   r<   r=   Úset_printer_settings‘  s   zWorksheet.set_printer_settingsc                 C   s   | j  |¡ dS )zÍ Add a data-validation object to the sheet.  The data-validation
            object defines the type of data-validation to be applied and the
            cell or range of cells it should apply to.
        N)rk   Úappend)rX   Údata_validationr<   r<   r=   Úadd_data_validationš  s   zWorksheet.add_data_validationc                 C   ó   |dur||_ | j |¡ dS )zd
        Add a chart to the sheet
        Optionally provide a cell for the top-left anchor
        N)Úanchorrc   r  )rX   Úchartr  r<   r<   r=   Ú	add_chart¢  ó   zWorksheet.add_chartc                 C   r  )zf
        Add an image to the sheet.
        Optionally provide a cell for the top-left anchor
        N)r  rd   r  )rX   Úimgr  r<   r<   r=   Ú	add_image¬  r  zWorksheet.add_imagec                 C   ó   | j  |¡ d S r6   )ri   r  )rX   Útabler<   r<   r=   Ú	add_table¶  ó   zWorksheet.add_tablec                 C   r  r6   )rj   r  )rX   Úpivotr<   r<   r=   Ú	add_pivotº  r  zWorksheet.add_pivotc                 C   s~   t |||||d�}	 | j |j¡ |j\}}}	}
t||
d ƒ}t||	d ƒ}t||ƒ}t|dd ƒD ]}|| jv r<| j|= q1d S )N©rñ   rÆ   rÇ   rÈ   rÉ   r!   )	r2   rh   rê   ÚcoordÚboundsr	   r   r   rb   )rX   rñ   Ú	start_rowÚstart_columnÚend_rowÚ
end_columnÚcrrÆ   rÇ   rÈ   rÉ   r·   r¸   Úcellsr;   r<   r<   r=   Úmerge_cells¾  s   ÿ

€þzWorksheet.merge_cellszUse ws.merged_cells.rangesc                 C   s   | j jdd… S )zReturn a copy of cell rangesN)rh   Úrangesr€   r<   r<   r=   Úmerged_cell_rangesÏ  s   zWorksheet.merged_cell_rangesc                 C   s>   t |||||d�}|j| jvrtd |j¡ƒ‚| j |¡ dS )zC Remove merge on a cell range.  Range is a cell range (e.g. A1:E1) r!  zCell range {0} is not mergedN)r2   r"  rh   rÀ   rÐ   Úremove)rX   rñ   r$  r%  r&  r'  r(  r<   r<   r=   Úunmerge_cellsÖ  s   ÿzWorksheet.unmerge_cellsc                 C   sò   | j d }t|tttfƒst|ƒrHt|dƒD ]0\}}t|tƒr7|}|jr-|j| kr-t	dƒ‚| |_||_
||_nt| |||d�}|| j||f< qn,t|tƒro| ¡ D ]\}}t|tƒr^t|ƒ}t| |||d�}|| j||f< qQn|  |¡ || _ dS )aµ  Appends a group of values at the bottom of the current sheet.

        * If it's a list: all values are added in order, starting from the first column
        * If it's a dict: values are assigned to the columns indicated by the keys (numbers or letters)

        :param iterable: list, range or generator, or dict containing values to append
        :type iterable: list|tuple|range|generator or dict

        Usage:

        * append(['This is A1', 'This is B1', 'This is C1'])
        * **or** append({'A' : 'This is A1', 'C' : 'This is C1'})
        * **or** append({1 : 'This is A1', 3 : 'This is C1'})

        :raise: TypeError when iterable is neither a list/tuple nor a dict

        r!   z,Cells cannot be copied from other worksheets)rA   rÃ   r8   N)rv   r®   r²   rÔ   r	   r   Ú	enumerater   rY   rÀ   rÃ   rA   rb   Údictrž   r
   r   Ú_invalid_row)rX   ÚiterableÚrow_idxrÃ   ÚcontentrÂ   r<   r<   r=   r  á  s0   
ÿ
õ

ü

zWorksheet.appendrA   c           	      C   s²   |dk}| j |d�}|dkr| j|d�}t|ƒ}t| j ¡ t|ƒ|d�}|D ]0}|r0|j|k r0q&|r8|j|k r8q&| j|j|jf= t	||ƒ}t
|||| ƒ || j|j|jf< q&dS )zB
        Move either rows or columns around by the offset
        r   )rÇ   rë   )rÆ   )rØ   ÚreverseN)rÖ   rÕ   r²   Úsortedrb   r¢   r   rA   rÃ   r›   rŸ   )	rX   rÇ   rÆ   ÚoffsetÚ
row_or_colr5  r)  rÂ   Úvalr<   r<   r=   Ú_move_cells  s    
õzWorksheet._move_cellsc                 C   ó   | j ||dd� dS )z4
        Insert row or rows before row==idx
        rA   ©rÇ   r7  r8  N©r:  ©rX   ÚidxÚamountr<   r<   r=   Úinsert_rows-  ó   zWorksheet.insert_rowsc                 C   r;  )z:
        Insert column or columns before col==idx
        rÃ   ©rÆ   r7  r8  Nr=  r>  r<   r<   r=   Úinsert_cols4  rB  zWorksheet.insert_colsc                 C   sd   t ||| jƒ}| j|| | dd� |D ]}t| j| jd ƒD ]}||f| jv r.| j||f= qqdS )z2
        Delete row or rows from row==idx
        rA   r<  r!   N)Ú_gutterrÉ   r:  r	   ré   r×   rb   )rX   r?  r@  Ú	remainderrA   rë   r<   r<   r=   Údelete_rows;  ó   €þÿzWorksheet.delete_rowsc                 C   sd   t ||| jƒ}| j|| | dd� |D ]}t| j| jd ƒD ]}||f| jv r.| j||f= qqdS )z8
        Delete column or columns from col==idx
        rÃ   rC  r!   N)rE  r×   r:  r	   rÇ   rÉ   rb   )rX   r?  r@  rF  rë   rA   r<   r<   r=   Údelete_colsJ  rH  zWorksheet.delete_colsc                 C   s   t d t|ƒ¡ƒ‚)NzQValue must be a list, tuple, range or generator, or a dict. Supplied value is {0})Ú	TypeErrorrÐ   r  )rX   r2  r<   r<   r=   r1  Y  s   ÿzWorksheet._invalid_rowc                 C   ó   t | ƒS )z(Dimension factory for column information)r&   r€   r<   r<   r=   r_   _  rî   zWorksheet._add_columnc                 C   rK  )z%Dimension factory for row information)r'   r€   r<   r<   r=   r]   d  rî   zWorksheet._add_rowc                 C   s<   ddl m} ddlm} |ƒ | _| j| j_| j| j_|| ƒS )Nr   )ÚSpreadsheetDrawing)Úwrite_worksheet)	Ú$openpyxl.drawing.spreadsheet_drawingrL  Úopenpyxl.writer.worksheetrM  rf   rc   Úchartsrd   Úimages)rX   rL  rM  r<   r<   r=   Ú_writej  s   

zWorksheet._writec                 C   ó   | j r| j S dS )z7Rows to be printed at the top of every page (ex: '1:3')N)rp   r€   r<   r<   r=   r»   s  ó   ÿzWorksheet.print_title_rowsc                 C   ó$   |durt  |¡stdƒ‚|| _dS )zV
        Set rows to be printed on the top of every page
        format `1:3`
        Nz%Print title rows must be the form 1:3)r   ÚmatchrÀ   rp   )rX   r·   r<   r<   r=   r»   z  ó   

c                 C   rS  )z@Columns to be printed at the left side of every page (ex: 'A:C')N)rq   r€   r<   r<   r=   rº   †  rT  zWorksheet.print_title_colsc                 C   rU  )zX
        Set cols to be printed on the left of every page
        format ``A:C`
        Nz%Print title cols must be the form C:D)r   rV  rÀ   rq   )rX   r¸   r<   r<   r=   rº   �  rW  c                 C   s*   | j r| jrd | j| j g¡S | jp| j S )Nú,)rº   r»   Újoinr€   r<   r<   r=   Úprint_titles™  s   zWorksheet.print_titlesc                 C   s   | j S )zˆ
        The print area for the worksheet, or None if not set. To set, supply a range
        like 'A1:D4' or a list of ranges.
        )rr   r€   r<   r<   r=   Ú
print_area¡  s   zWorksheet.print_areac                 C   s$   t |tƒr|g}dd„ |D ƒ| _dS )zD
        Range of cells in the form A1:D4 or list of ranges
        c                 S   s   g | ]}t |ƒ‘qS r<   )r   )r:   r¡   r<   r<   r=   Ú
<listcomp>²  s    z(Worksheet.print_area.<locals>.<listcomp>N)r®   r
   rr   )rX   r8   r<   r<   r=   r[  ª  s   
r6   )r·   )NNNNNr   r   )NNNN)NNNNN)NNr   rA   )r!   )VÚ__name__Ú
__module__Ú__qualname__Ú__doc__Ú	_rel_typeÚ_pathÚ	mime_typeÚ
BREAK_NONEÚ	BREAK_ROWÚBREAK_COLUMNÚSHEETSTATE_VISIBLEÚSHEETSTATE_HIDDENÚSHEETSTATE_VERYHIDDENÚPAPERSIZE_LETTERÚPAPERSIZE_LETTER_SMALLÚPAPERSIZE_TABLOIDÚPAPERSIZE_LEDGERÚPAPERSIZE_LEGALÚPAPERSIZE_STATEMENTÚPAPERSIZE_EXECUTIVEÚPAPERSIZE_A3ÚPAPERSIZE_A4ÚPAPERSIZE_A4_SMALLÚPAPERSIZE_A5r  r  rV   rW   Úpropertyr‚   r†   r‰   r‹   rŽ   r�   r�   Úsetterr   r£   r¦   r¿   rÂ   rÁ   rÄ   rÙ   rÚ   rÝ   rÞ   rÇ   rÉ   ré   r×   rì   rí   rÖ   rð   r·   r¢   rÕ   rú   rü   rý   r  r  r  r  r  r  r   r*  r,  r.  r  r:  rA  rD  rG  rI  r1  r_   r]   rR  r»   rº   rZ  r[  r<   r<   r<   r=   rC   T   sò    
&









#

)





ÿ8


	%	


"	






0



	





rC   c                 C   s&   t t|d | | ƒt| | |ƒƒ}|S )zÈ
    When deleting rows and columns are deleted we rely on overwriting.
    This may not be the case for a large offset on small set of cells:
    range(cells_to_delete) > range(cell_to_be_moved)
    r!   )r	   rÅ   rå   )r?  r7  Úmax_valÚgutterr<   r<   r=   rE  µ  s   "rE  )OÚ
__future__r   Ú	itertoolsr   r   Úoperatorr   ÚreÚinspectr   Úwarningsr   Úopenpyxl.compatr   r	   r
   r   r   Úopenpyxl.utilsr   r   r   r   r   r   r   Úopenpyxl.utils.cellr   Úopenpyxl.cellr   Úopenpyxl.utils.exceptionsr   r   Úopenpyxl.utils.unitsr   r   r   Úopenpyxl.formatting.formattingr   Úopenpyxl.packaging.relationshipr   Úopenpyxl.workbook.childr   Úopenpyxl.workbook.defined_namer   r   Úopenpyxl.utils.bound_dictionaryr    Údatavalidationr"   Úpager#   r$   r%   rí   r&   r'   r(   r)   ru   r*   Úfiltersr+   r,   rt   r-   r.   r/   r0   Ú
cell_ranger1   r2   Ú
propertiesr3   Ú	pagebreakr4   rB   rC   rE  r<   r<   r<   r=   Ú<module>   sJ    $		
      g