How to use the xlrd.error_text_from_code function in xlrd

To help you get started, we’ve selected a few xlrd examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github python-excel / xlrd / examples / xlrdnameAPIdemo.py View on Github external
def showable_cell_value(celltype, cellvalue, datemode):
    if celltype == xlrd.XL_CELL_DATE:
        try:
            showval = xlrd.xldate_as_tuple(cellvalue, datemode)
        except xlrd.XLDateError as e:
            showval = "%s:%s" % (type(e).__name__, e)
    elif celltype == xlrd.XL_CELL_ERROR:
        showval = xlrd.error_text_from_code.get(
            cellvalue, '' % cellvalue)
    else:
        showval = cellvalue
    return showval
github rwl / pylon / pylon / dss / ukgds2dss.py View on Github external
# The type associated with the value.
        value_type = type_codes[types[i]]

        # Coerce float value types.
        if value_type is "float":
            # Coerce to integers.
            if value == int(value):
                value = int(value)

        # Format dates as a tuple.
        elif value_type is "date":
            value = xlrd.xldate_as_tuple(value, book.datemode)

        # Extract error text.
        elif value_type is "error":
            value = xlrd.error_text_from_code[value]

        return_row.append(value)

    return return_row
github extrabacon / xlrd-parser / xlrd-parser.py View on Github external
def parse_cell_value(sheet, cell):
  if cell.ctype == xlrd.XL_CELL_DATE:
    year, month, day, hour, minute, second = xldate_as_tuple(cell.value, sheet.book.datemode)
    return ['date', year, month, day, hour, minute, second]
  elif cell.ctype == xlrd.XL_CELL_ERROR:
    return ['error', error_text_from_code[cell.value]]
  elif cell.ctype == xlrd.XL_CELL_BOOLEAN:
    return False if cell.value == 0 else True
  elif cell.ctype == xlrd.XL_CELL_EMPTY:
    return None
  return cell.value
github wxWidgets / Phoenix / wx / lib / agw / xlsgrid.py View on Github external
ctype, value = cell.ctype, cell.value

        self.value = "%s"%value
        isDate = False

        if ctype == xlrd.XL_CELL_DATE:
            value = xlrd.xldate_as_tuple(value, datemode)
            isDate = True
        elif ctype in [xlrd.XL_CELL_EMPTY, xlrd.XL_CELL_BLANK]:
            return
        elif ctype == xlrd.XL_CELL_TEXT:
            self.value = "%s"%value
            return
        elif ctype == xlrd.XL_CELL_ERROR:
            value = xlrd.error_text_from_code(ctype)
            self.value = "%s"%value
            return

        self.FormatString(value, isDate, format.format_str)
github roskakori / cutplace / cutplace / rowio.py View on Github external
:param str datemode: the datemode from the workbook the cell was read \
      from; refer to the :py:mod:`xlrd` documentation for more details
    """
    assert cell is not None

    if cell.ctype == xlrd.XL_CELL_DATE:
        cell_tuple = xlrd.xldate_as_tuple(cell.value, datemode)
        assert len(cell_tuple) == 6, "cell_tuple=%r" % cell_tuple
        if cell_tuple[:3] == (0, 0, 0):
            time_tuple = cell_tuple[3:]
            result = six.text_type(datetime.time(*time_tuple))
        else:
            result = six.text_type(datetime.datetime(*cell_tuple))
    elif cell.ctype == xlrd.XL_CELL_ERROR:
        default_error_text = xlrd.error_text_from_code[0x2a]  # same as "#N/A!"
        error_code = cell.value
        result = six.text_type(xlrd.error_text_from_code.get(error_code, default_error_text))
    elif isinstance(cell.value, six.text_type):
        result = cell.value
    else:
        result = six.text_type(cell.value)
        if (cell.ctype == xlrd.XL_CELL_NUMBER) and (result.endswith(".0")):
            result = result[:-2]

    return result
github pythonanywhere / dirigible-spreadsheet / python / dirigible / sheet / worksheet.py View on Github external
def worksheet_from_excel(excel_sheet):
    worksheet = Worksheet()
    for col in range(excel_sheet.ncols):
        for row in range(excel_sheet.nrows):
            cell = excel_sheet.cell(row, col)
            if cell.ctype == XL_CELL_ERROR:
                formula = '=%s' % (error_text_from_code[cell.value], )
            elif cell.ctype == XL_CELL_DATE:
                formula = '=DateTime(%s, %s, %s, %s, %s, %s)' % xldate_as_tuple(
                    cell.value, excel_sheet.book.datemode)
            else:
                formula = unicode(excel_sheet.cell(row, col).value)
            worksheet[col + 1, row + 1].formula = formula
    return worksheet
github roskakori / cutplace / cutplace / _parsers.py View on Github external
assert cell is not None

    # Just import without sanitizing the error message. If we got that far, the import should have worked
    # already.
    import xlrd

    if cell.ctype == xlrd.XL_CELL_DATE:
        cellTuple = xlrd.xldate_as_tuple(cell.value, datemode)
        assert len(cellTuple) == 6, "cellTuple=%r" % cellTuple
        if cellTuple[:3] == (0, 0, 0):
            timeTuple = cellTuple[3:]
            result = str(datetime.time(*timeTuple))
        else:
            result = str(datetime.datetime(*cellTuple))
    elif cell.ctype == xlrd.XL_CELL_ERROR:
        defaultErrorText = xlrd.error_text_from_code[0x2a]  # same as "#N/A!"
        errorCode = cell.value
        result = str(xlrd.error_text_from_code.get(errorCode, defaultErrorText), "ascii")
    elif isinstance(cell.value, str):
        result = cell.value
    else:
        result = str(cell.value)
        if (cell.ctype == xlrd.XL_CELL_NUMBER) and (result.endswith(".0")):
            result = result[:-2]

    return result
github python-excel / xlrd / xlrd / examples / xlrdnameAPIdemo_py3.py View on Github external
def showable_cell_value(celltype, cellvalue, datemode):
    if celltype == xlrd.XL_CELL_DATE:
        try:
            showval = xlrd.xldate_as_tuple(cellvalue, datemode)
        except xlrd.XLDateError:
            e1, e2 = sys.exc_info()[:2]
            showval = "%s:%s" % (e1.__name__, e2)
    elif celltype == xlrd.XL_CELL_ERROR:
        showval = xlrd.error_text_from_code.get(
            cellvalue, '' % cellvalue)
    else:
        showval = cellvalue
    return showval
github extrabacon / pyspreadsheet / python / excel_reader.py View on Github external
def parse_cell_value(sheet, cell):
  if cell.ctype == xlrd.XL_CELL_DATE:
    year, month, day, hour, minute, second = xldate_as_tuple(cell.value, sheet.book.datemode)
    return ['date', year, month, day, hour, minute, second]
  elif cell.ctype == xlrd.XL_CELL_ERROR:
    return ['error', error_text_from_code[cell.value]]
  elif cell.ctype == xlrd.XL_CELL_BOOLEAN:
    return False if cell.value == 0 else True
  elif cell.ctype == xlrd.XL_CELL_EMPTY:
    return None
  return cell.value