The Sheet Object

class Sheet(book, position, name, number)

Contains the data for one worksheet.

In the cell access functions, “rowx” is a row index, counting from zero, and “colx” is acolumn index, counting from zero. Negative values for row/column indexes and slice positions are supported in the expected fashion.

For information about cell types and cell values, refer to the documentation of the Cell class.

Warning

You don’t call this class yourself. You access Sheet objects via the Book object that was returned when you called open_workbook().

col_label_ranges

List of address ranges of cells containing column labels. These are set up in Excel by Insert > Name > Labels > Columns.

  • New in version 0.6.0

How to deconstruct the list:

for crange in thesheet.col_label_ranges:
    rlo, rhi, clo, chi = crange
    for rx in xrange(rlo, rhi):
        for cx in xrange(clo, chi):
            print "Column label at (rowx=%d, colx=%d) is %r" \
                (rx, cx, thesheet.cell_value(rx, cx))
Sheet.colinfo_map

The map from a column index to a Colinfo object. Often there is an entry in COLINFO records for all column indexes in range(257).

Note that xlrd ignores the entry for the non-existent 257th column. On the other hand, there may be no entry for unused columns.

  • New in version 0.6.1
Sheet.default_additional_space_above

Default value to be used for a row if there is no ROW record for that row.

From the optional DEFAULTROWHEIGHT record.

Sheet.default_additional_space_below

Default value to be used for a row if there is no ROW record for that row.

From the optional DEFAULTROWHEIGHT record.

Sheet.default_row_height

Default value to be used for a row if there is no ROW record for that row.

From the optional DEFAULTROWHEIGHT record.

Sheet.default_row_hidden

Default value to be used for a row if there is no ROW record for that row.

From the optional DEFAULTROWHEIGHT record.

Sheet.defcolwidth

Default column width from DEFCOLWIDTH record, else None.

From the OOo docs:

“Column width in characters, using the width of the zero character from default font (first FONT record in the file). Excel adds some extra space to the default width, depending on the default font and default font size. The algorithm how to exactly calculate the resulting column width is not known.<br /> Example: The default width of 8 set in this record results in a column width of 8.43 using Arial font with a size of 10 points.”

For the default hierarchy, refer to the Colinfo class above.

  • New in version 0.6.1
Sheet.gcw

A 256-element tuple corresponding to the contents of the GCW record for this sheet.

If no such record, treat as all bits zero.

Applies to BIFF4-7 only. See docs of Colinfo class for discussion.

Sheet.merged_cells

List of address ranges of cells which have been merged.

These are set up in Excel by Format > Cells > Alignment, then ticking the “Merge cells” box.

  • New in version 0.6.1. Extracted only if open_workbook(..., formatting_info=True)

How to deconstruct the list:

for crange in thesheet.merged_cells:
    rlo, rhi, clo, chi = crange
    for rowx in xrange(rlo, rhi):
        for colx in xrange(clo, chi):
            # cell (rlo, clo) (the top left one) will carry the data
            # and formatting info; the remainder will be recorded as
            # blank cells, but a renderer will apply the formatting info
            # for the top left cell (e.g. border, pattern) to all cells in
            # the range.
Sheet.name

Name of sheet.

Sheet.ncols

Number of columns in sheet. A column index is in range(thesheet.ncols).

Sheet.nrows

Number of rows in sheet. A row index is in range(thesheet.nrows).

Sheet.rowinfo_map

The map from a row index to a Rowinfo object. Note that it is possible to have missing entries – at least one source of XLS files doesn’t bother writing ROW records.

  • New in version 0.6.1
Sheet.standardwidth

Default column width from STANDARDWIDTH record, else None.

From the OOo docs:

“Default width of the columns in 1/256 of the width of the zero character, using default font (first FONT record in the file).”

For the default hierarchy, refer to the Colinfo class above.

  • New in version 0.6.1
Sheet.visibility

Visibility of the sheet. 0 = visible, 1 = hidden (can be unhidden by user – Format/Sheet/Unhide), 2 = “very hidden” (can be unhidden only by VBA macro).

Sheet.cell(rowx, colx)

Cell object in the given row and column.

Sheet.cell_type(rowx, colx)

Type of the cell in the given row and column. Refer to the documentation of the Cell class.

Shett.cell_value(rowx, colx)

Value of the cell in the given row and column.

cell_xf_index(rowx, colx)

XF index of the cell in the given row and column. This is an index into Book.xf_list.

  • New in version 0.6.1
Sheet.col(colx)

Returns a sequence of the Cell objects in the given column.

Sheet.col_slice(colx, start_rowx=0, end_rowx=None)

Returns a slice of the Cell objects in the given column.

Sheet.col_types(colx, start_rowx=0, end_rowx=None)

Returns a slice of the types of the cells in the given column.

Sheet.col_values(colx, start_rowx=0, end_rowx=None)

Returns a slice of the values of the cells in the given column.

Sheet.computed_column_width(colx)

Determine column display width.

  • New in version 0.6.1
Parameters:
  • colx (int) – Index of the queried column, range 0 to 255. Note that it is possible to find out the width that will be used to display columns with no cell information e.g. column IV (colx=255).
Returns:

The column width that will be used for displaying the given column by Excel, in units of 1/256th of the width of a standard character (the digit zero in the first font).

Sheet.row(rowx)

Returns a sequence of the Cell objects in the given row.

Sheet.row_label_ranges

List of address ranges of cells containing row labels.

For more details, see <i>col_label_ranges</i> above.

  • New in version 0.6.0
Sheet.row_slice(rowx, start_colx=0, end_colx=None)

Returns a slice of the Cell objects in the given row.

Sheet.row_types(rowx, start_colx=0, end_colx=None)

Returns a slice of the types of the cells in the given row.

Sheet.row_values(rowx, start_colx=0, end_colx=None)

Returns a slice of the values of the cells in the given row.

Previous topic

The Rowinfo Object

Next topic

The XF Object

This Page