atomica.excel.cell_get_number

atomica.excel.cell_get_number(cell, dtype=<class 'float'>)[source]

Return numeric value from cell

This function is to guard against accidentally having the Excel cell contain a string instead of a number. If a string has been entered, an error will be raised. The added value from this function is that if the Excel cell type is empty but the value is empty or N.A. then the value will be treated as though the cell was correctly set to a numeric type but had been left empty.

The output is cast to dtype which means that code that requires numeric input from Excel can use this input to guarantee that the resulting number is of the correct type, or None.

Parameters:
  • cell – An openpyxl cell

  • dtype – If the cell is numeric, cast to this type (default is float but could be int for example)

Returns:

A scalar instance of dtype (e.g. float) or None if cell is empty or being treated as empty

Raises:

Exception if the cell contains a string