Contains the data for one cell. (XFCell is the base class of Cell)
WARNING: You don’t call this class yourself. You access Cell objects via methods of the Sheet object(s) that you found in the Book object that was returned when you called open_workbook().
Cell objects have three attributes:
is an int
If “formatting_info” is not enabled when the workbook is opened, xf_index will be None. The following table describes the types of cells and how their values are represented in Python.
Type symbol | Type number | Python value |
---|---|---|
XL_CELL_EMPTY | 0 | empty string ‘’ |
XL_CELL_TEXT | 1 | a Unicode string |
XL_CELL_NUMBER | 2 | float |
XL_CELL_DATE | 3 | float |
XL_CELL_BOOLEAN | 4 | int; 1 means True, 0 means False |
XL_CELL_ERROR | 5 | int representing internal Excel codes; for a text representation, refer to the supplied dictionary error_text_from_code |
XL_CELL_BLANK | 6 | empty string ‘’. Note: this type will appear only when open_workbook(..., formatting_info= True) is used. |
Add convenient methods and attributes for easy access of cell properties. (XFCell is the base class of Cell!)
True if cell has a xf record. Workbook was opened with formatting_info=True.
Get rgb-tuple of color index.
True if cell type is XL_CELL_DATE.
True if cell has a valid date and not only a time.
Returns a datetime.datetime object if cell type is XL_CELL_DATE else raises a TypeError. Raises ValueError if the cell does not have a date value (only a time value is present).
Returns a datetime.date object if cell type is XL_CELL_DATE else raises a TypeError. Raises ValueError if the cell does not have a date value (only a time value is present).
Returns a datetime.time object if cell type is XL_CELL_DATE else raises a TypeError.
Get the XFBackground object.
Get the background color as rgb-tuple.
Get the pattern color as rgb-tuple.
Get the fill pattern. see XFBackground.fill_pattern
Get the font color as rgb-tuple.
Get the Format.format_str.
Get the XFAlignment object.
Get border colors as dict of rgb-color-tuples.
keys: ‘top’, ‘bottom’, ‘left’, ‘right’, ‘diag’
example get rgb-values for the top cell border:
colors = cell.bordercolors()
r,g,b = colors['top']
Get border styles as dict of int. Border styles see XFBorder
keys: ‘top’, ‘bottom’, ‘left’, ‘right’, ‘diag’
If True draw a line across the cell from bottom left to top right.
If True draw a line across the cell from top left to bottom right.