Coverage for pandalone.xleash.io._xlrd : 81%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/env python # -*- coding: UTF-8 -*- # # Copyright 2014 European Commission (JRC); # Licensed under the EUPL (the 'Licence'); # You may not use this work except in compliance with the Licence. # You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl Implements the *xlrd* backend of *xleash* that reads in-file Excel-spreadsheets.
.. currentmodule:: pandalone.xleash """
XL_CELL_BLANK, XL_CELL_ERROR, XL_CELL_BOOLEAN, XL_CELL_NUMBER)
# noinspection PyUnresolvedReferences else: _xlrd_0_9_3 = False
""" Parse a xl-xcell.
:param xlrd.Cell xcell: an excel xcell :type xcell: xlrd.sheet.Cell
:param epoch1904: Which date system was in force when this file was last saved. False => 1900 system (the Excel for Windows default). True => 1904 system (the Excel for Macintosh default). :type epoch1904: bool
:return: formatted xcell value :rtype: int, float, datetime.datetime, bool, None, str, datetime.time, float('nan')
Examples::
>>> import xlrd >>> from xlrd.sheet import Cell >>> _parse_cell(Cell(xlrd.XL_CELL_NUMBER, 1.2)) 1.2
>>> _parse_cell(Cell(xlrd.XL_CELL_DATE, 1.2)) datetime.datetime(1900, 1, 1, 4, 48)
>>> _parse_cell(Cell(xlrd.XL_CELL_TEXT, 'hi')) 'hi' """
# GH5394 - Excel 'numbers' are always floats # it's a minimal perf hit and less suprising return None # RECT-LOOP NEVER USE THIS # Use the newer xlrd datetime handling.
# 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. d = datetime.time(d.hour, d.minute, d.second, d.microsecond) else: # Use the xlrd <= 0.9.2 date handling. d = xldate.xldate_as_tuple(xcell.value, epoch1904) if d[0] < datetime.MINYEAR: # time d = datetime.time(*d[3:]) else: # date d = datetime.datetime(*d) elif ctype == XL_CELL_ERROR: return float('nan')
raise ValueError('Invalid XL-cell type(%s) for value(%s)!' % (xcell.ctype, xcell.value))
""" :param int or str or None sheet_id: If `None`, opens 1st sheet. :param dict opts: does nothing with them """ else: except Exception as xl_ex: try: sheet_id = int(sheet_id) except ValueError: raise xl_ex else: xl_sh = xlrd_book.sheet_by_index(sheet_id)
""" Opens the local or remote `wb_url` *xlrd* workbook wrapped as :class:`XlrdSheet`. """ else: ropts.pop('on_demand', None) http_opts = ropts.get('http_opts', {}) with request.urlopen(wb_url, **http_opts) as response: log.info('Opening book %r...', filename) book = xlrd.open_workbook( filename, file_contents=response, **ropts)
""" The *xlrd* workbook wrapper required by xleash library. """
raise ValueError("Invalid xlrd-sheet({})".format(sheet))
""" Override it to release resources for this sheet.""" self._sheet.book.unload_sheet(self._sheet.name)
""" Override it to release resources this and all sibling sheets.""" #self._sheet.book.release_resources()
[sh.name, sh.number])
"""Gets by-index only if `sheet_id` is `int`, otherwise tries both by name and index.""" self.book_fname, sheet_id, opts)
"""See super-method. """
"""See super-method. """
|