How to use the pyexcelerate.DataTypes.DataTypes function in PyExcelerate

To help you get started, we’ve selected a few PyExcelerate 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 kz26 / PyExcelerate / pyexcelerate / DataTypes.py View on Github external
if len(value) > 0 and value[0] == '=':
                return DataTypes.FORMULA
            else:
                return DataTypes.INLINE_STRING
        elif isinstance(value, bool):
            return DataTypes.BOOLEAN
        elif isinstance(value, DataTypes._numberTypes):
            return DataTypes.NUMBER
        elif HAS_NUMPY and isinstance(
                value,
            (np.floating, np.integer, np.complexfloating, np.unsignedinteger)):
            return DataTypes.NUMBER
        elif isinstance(value, (datetime, date, time)):
            return DataTypes.DATE
        else:
            return DataTypes.ERROR
github kz26 / PyExcelerate / pyexcelerate / DataTypes.py View on Github external
elif value.__class__ in DataTypes._numberTypes:
            return DataTypes.NUMBER
        # fall back to the slower isinstance
        elif isinstance(value, six.string_types):
            if len(value) > 0 and value[0] == '=':
                return DataTypes.FORMULA
            else:
                return DataTypes.INLINE_STRING
        elif isinstance(value, bool):
            return DataTypes.BOOLEAN
        elif isinstance(value, DataTypes._numberTypes):
            return DataTypes.NUMBER
        elif HAS_NUMPY and isinstance(
                value,
            (np.floating, np.integer, np.complexfloating, np.unsignedinteger)):
            return DataTypes.NUMBER
        elif isinstance(value, (datetime, date, time)):
            return DataTypes.DATE
        else:
            return DataTypes.ERROR
github kz26 / PyExcelerate / pyexcelerate / DataTypes.py View on Github external
def get_type(value):
        # Using value.__class__ over isinstance for speed
        if value.__class__ in six.string_types:
            if len(value) > 0 and value[0] == '=':
                return DataTypes.FORMULA
            else:
                return DataTypes.INLINE_STRING
        # not using in (int, float, long, complex) for speed
        elif value.__class__ == bool:
            return DataTypes.BOOLEAN
        elif value.__class__ in DataTypes._numberTypes:
            return DataTypes.NUMBER
        # fall back to the slower isinstance
        elif isinstance(value, six.string_types):
            if len(value) > 0 and value[0] == '=':
                return DataTypes.FORMULA
            else:
                return DataTypes.INLINE_STRING
        elif isinstance(value, bool):
            return DataTypes.BOOLEAN
        elif isinstance(value, DataTypes._numberTypes):
            return DataTypes.NUMBER
        elif HAS_NUMPY and isinstance(
                value,
            (np.floating, np.integer, np.complexfloating, np.unsignedinteger)):
            return DataTypes.NUMBER
        elif isinstance(value, (datetime, date, time)):
github kz26 / PyExcelerate / pyexcelerate / Worksheet.py View on Github external
def __get_cell_data(self, cell, x, y, style):
        if cell is None:
            return ""  # no cell data
        # boolean values are treated oddly in dictionaries, manually override
        type = DataTypes.get_type(cell)

        if type == DataTypes.NUMBER:
            if math.isnan(cell):
                z = '" t="e">#NUM!'
            elif math.isinf(cell):
                z = '" t="e">#DIV/0!'
            else:
                z = '">%.15g' % (cell)
        elif type == DataTypes.INLINE_STRING:
            z = '" t="inlineStr">%s' % escape(
                to_unicode(cell))
        elif type == DataTypes.DATE:
            z = '">%s' % (DataTypes.to_excel_date(cell))
        elif type == DataTypes.FORMULA:
            z = '">%s' % (cell[1:]) # Remove equals sign.
        elif type == DataTypes.BOOLEAN:
            z = '" t="b">%d' % (cell)

        if style:
            return "
github kz26 / PyExcelerate / pyexcelerate / Worksheet.py View on Github external
def __get_cell_data(self, cell, x, y, style):
        if cell is None:
            return ""  # no cell data
        # boolean values are treated oddly in dictionaries, manually override
        type = DataTypes.get_type(cell)

        if type == DataTypes.NUMBER:
            if math.isnan(cell):
                z = '" t="e">#NUM!'
            elif math.isinf(cell):
                z = '" t="e">#DIV/0!'
            else:
                z = '">%.15g' % (cell)
        elif type == DataTypes.INLINE_STRING:
            z = '" t="inlineStr">%s' % escape(
                to_unicode(cell))
        elif type == DataTypes.DATE:
            z = '">%s' % (DataTypes.to_excel_date(cell))
        elif type == DataTypes.FORMULA:
            z = '">%s' % (cell[1:]) # Remove equals sign.
        elif type == DataTypes.BOOLEAN:
            z = '" t="b">%d' % (cell)
github kz26 / PyExcelerate / pyexcelerate / DataTypes.py View on Github external
def to_excel_date(d):
        if isinstance(d, datetime):
            if d.tzinfo is not None:
                warnings.warn(
                    'Excel does not support timestamps with time zone information. Time zones will be ignored.'
                )
            delta = d.replace(tzinfo=None) - DataTypes.EXCEL_BASE_DATE
            excel_date = delta.days + (
                float(delta.seconds) + float(delta.microseconds) / 1E6) / (
                    60 * 60 * 24) + 1
            return excel_date + (excel_date > 59)
        elif isinstance(d, date):
            # this is why python sucks >.<
            return DataTypes.to_excel_date(datetime(*(d.timetuple()[:6])))
        elif isinstance(d, time):
            return DataTypes.to_excel_date(
                datetime(
                    *(DataTypes.EXCEL_BASE_DATE.timetuple()[:3]),
                    hour=d.hour,
                    minute=d.minute,
                    second=d.second,
                    microsecond=d.microsecond)) - 1
github kz26 / PyExcelerate / pyexcelerate / Worksheet.py View on Github external
if type == DataTypes.NUMBER:
            if math.isnan(cell):
                z = '" t="e">#NUM!'
            elif math.isinf(cell):
                z = '" t="e">#DIV/0!'
            else:
                z = '">%.15g' % (cell)
        elif type == DataTypes.INLINE_STRING:
            z = '" t="inlineStr">%s' % escape(
                to_unicode(cell))
        elif type == DataTypes.DATE:
            z = '">%s' % (DataTypes.to_excel_date(cell))
        elif type == DataTypes.FORMULA:
            z = '">%s' % (cell[1:]) # Remove equals sign.
        elif type == DataTypes.BOOLEAN:
            z = '" t="b">%d' % (cell)

        if style:
            return "