How to use the pyexcelerate.DataTypes.DataTypes.to_excel_date 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
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 / 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
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 "