msl.io.readers.excel module

Read an Excel spreadsheet (.xls and .xlsx).

class msl.io.readers.excel.ExcelReader(file, **kwargs)[source]

Bases: Spreadsheet

Read an Excel spreadsheet (.xls and .xlsx).

This class simply provides a convenience for reading information from Excel spreadsheets. It is not registered as a Reader because the information in an Excel spreadsheet is unstructured and therefore one cannot generalize how to parse an Excel spreadsheet to create a Root.

Parameters:
  • file (str) – The location of an Excel spreadsheet on a local hard drive or on a network.

  • **kwargs – All keyword arguments are passed to open_workbook(). Can use an encoding keyword argument as an alias for encoding_override. The default on_demand value is True.

Examples

>>> from msl.io import ExcelReader  
>>> excel = ExcelReader('lab_environment.xlsx')  
close()[source]

Calls release_resources().

read(cell=None, sheet=None, as_datetime=True)[source]

Read values from the Excel spreadsheet.

Parameters:
  • cell (str, optional) – The cell(s) to read. For example, C9 will return a single value and C9:G20 will return all values in the specified range. If not specified then returns all values in the specified sheet.

  • sheet (str, optional) – The name of the sheet to read the value(s) from. If there is only one sheet in the spreadsheet then you do not need to specify the name of the sheet.

  • as_datetime (bool, optional) – Whether dates should be returned as datetime or date objects. If False then dates are returned as an ISO 8601 string.

Returns:

The value(s) of the requested cell(s).

Examples

>>> excel.read()
[('temperature', 'humidity'), (20.33, 49.82), (20.23, 46.06), (20.41, 47.06), (20.29, 48.32)]
>>> excel.read('B2')
49.82
>>> excel.read('A:A')
[('temperature',), (20.33,), (20.23,), (20.41,), (20.29,)]
>>> excel.read('A1:B1')
[('temperature', 'humidity')]
>>> excel.read('A2:B4')
[(20.33, 49.82), (20.23, 46.06), (20.41, 47.06)]
sheet_names()[source]

Get the names of all sheets in the Excel spreadsheet.

Returns:

tuple of str – The names of all sheets.

property workbook

The workbook instance.

Type:

Book