How to use the xlrd.XL_CELL_DATE 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 frictionlessdata / tabulator-py / tabulator / parsers / View on Github external
def type_value(ctype, value):
            """ Detects boolean value, int value, datetime """

            # Boolean
            if ctype == xlrd.XL_CELL_BOOLEAN:
                return bool(value)

            # Excel numbers are only float
            # Float with no decimals can be cast into int
            if ctype == xlrd.XL_CELL_NUMBER and value == value // 1:
                return int(value)

            # Datetime
            if ctype == xlrd.XL_CELL_DATE:
                return xlrd.xldate.xldate_as_datetime(value, self.__book.datemode)

            return value
github python-excel / xlutils / xlutils / View on Github external
def __row(self, rowx):
        for colx in self.cols:
            value = self.sheet.cell_value(rowx, colx)
            if self.sheet.cell_type(rowx, colx) == XL_CELL_DATE:
                date_parts = xldate_as_tuple(value,
                # Times come out with a year of 0.
                if date_parts[0]:
                    value = datetime(*date_parts)
                    value = time(*date_parts[3:])
            yield value
github pandas-dev / pandas / pandas / io / View on Github external
def _parse_cell(cell_contents, cell_typ):
            """converts the contents of the cell into a pandas
               appropriate object"""

            if cell_typ == XL_CELL_DATE:

                # Use the newer xlrd datetime handling.
                    cell_contents = xldate.xldate_as_datetime(
                        cell_contents, epoch1904)
                except OverflowError:
                    return cell_contents

                # Excel doesn't distinguish between dates and time,
                # so we treat dates on the epoch as times only.
                # Also, Excel supports 1900 and 1904 epochs.
                year = (cell_contents.timetuple())[0:3]
                if ((not epoch1904 and year == (1899, 12, 31)) or
                        (epoch1904 and year == (1904, 1, 1))):
                    cell_contents = time(cell_contents.hour,
github wq / itertable / itertable / parsers / View on Github external
def get_value(self, cell):
        if cell.ctype == xlrd.XL_CELL_DATE:
            time, date = math.modf(cell.value)
            tpl = xlrd.xldate_as_tuple(cell.value, self.workbook.datemode)
            if date and time:
                return datetime.datetime(*tpl)
            elif date:
                return datetime.time(*tpl[3:6])
        return cell.value
github deanishe / i-sheet-you-not / src / isheetyounot / View on Github external
str: Formatted cell value

        if cell.ctype == TYPE_BOOLEAN:
            if cell.value:
                return 'yes'
                return 'no'

        if cell.ctype == TYPE_ERROR:
            return ''

        if cell.ctype == TYPE_EMPTY:
            return ''

        if cell.ctype == TYPE_DATE:
            dt = xldate_as_datetime(cell.value, self.datemode)
            return dt.strftime(DATE_FORMAT)

        return cell.value
github sahana / eden / modules / s3 / View on Github external
                    Helper method to decode the cell value by type

                    @param t: the cell type
                    @param v: the cell value
                    @return: text representation of the cell value
                text = ""
                if v:
                    if t is None:
                        text = s3_unicode(v).strip()
                    elif t == xlrd.XL_CELL_TEXT:
                        text = v.strip()
                    elif t == xlrd.XL_CELL_NUMBER:
                        text = str(long(v)) if long(v) == v else str(v)
                    elif t == xlrd.XL_CELL_DATE:
                        # Convert into an ISO datetime string
                        text = s3_encode_iso_datetime(decode_date(v))
                    elif t == xlrd.XL_CELL_BOOLEAN:
                        text = str(v).lower()
                return text
github pythonanywhere / dirigible-spreadsheet / python / dirigible / sheet / 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(
                formula = unicode(excel_sheet.cell(row, col).value)
            worksheet[col + 1, row + 1].formula = formula
    return worksheet
github nyaruka / smartmin / smartmin / View on Github external
def get_cell_value(cls, workbook, tz, cell):
        if cell.ctype == XL_CELL_DATE:
            date = xldate_as_tuple(cell.value, workbook.datemode)
            return datetime.datetime(*date, tzinfo=tz)
            return cls.normalize_value(str(cell.value))
github pyexcel / pyexcel-xls / pyexcel_xls / View on Github external
def cell_value(self, row, column):
        Random access to the xls cells
        if self._keywords.get("skip_hidden_row_and_column") is True:
            row, column = self._offset_hidden_indices(row, column)
        cell_type = self._native_sheet.cell_type(row, column)
        value = self._native_sheet.cell_value(row, column)

        if cell_type == xlrd.XL_CELL_DATE:
            value = xldate_to_python_date(value, self._book_date_mode)
        elif cell_type == xlrd.XL_CELL_NUMBER and self.__auto_detect_int:
            if has_no_digits_in_float(value):
                value = int(value)
        elif cell_type == xlrd.XL_CELL_ERROR:
            value = DEFAULT_ERROR_VALUE

        if self.__merged_cells:
            merged_cell = self.__merged_cells.get("%s-%s" % (row, column))
            if merged_cell:
                if merged_cell.value:
                    value = merged_cell.value
                    merged_cell.value = value
        return value
github okfn / datautil / swiss / tabular / View on Github external
def cell_to_python(self, cell, book):
        # annoying need book argument for datemode
        # info on types:
        if cell.ctype == xlrd.XL_CELL_NUMBER: 
            return float(cell.value)
        elif cell.ctype == xlrd.XL_CELL_DATE:
            from datetime import date
            # TODO: distinguish date and datetime
            args = xlrd.xldate_as_tuple(cell.value, book.datemode)
                return date(args[0], args[1], args[2])
            except Exception, inst:
                print 'Error parsing excel date (%s): %s' % (args, inst)
                return None
        elif cell.ctype == xlrd.XL_CELL_BOOLEAN:
            return bool(cell.value)
            return cell.value