當前位置: 首頁>>代碼示例>>Python>>正文


Python xlrd.Book方法代碼示例

本文整理匯總了Python中xlrd.Book方法的典型用法代碼示例。如果您正苦於以下問題:Python xlrd.Book方法的具體用法?Python xlrd.Book怎麽用?Python xlrd.Book使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在xlrd的用法示例。


在下文中一共展示了xlrd.Book方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_workbooks

# 需要導入模塊: import xlrd [as 別名]
# 或者: from xlrd import Book [as 別名]
def get_workbooks(self):
        """
        If the data to be processed is not stored in files or if
        special parameters need to be passed to :func:`xlrd.open_workbook`
        then this method must be overriden.
        Any implementation must return an iterable sequence of tuples.
        The first element of which must be an :class:`xlrd.Book` object and the
        second must be the filename of the file from which the book
        object came.
        """
        for path in self.get_filepaths():
            yield (
                xlrd.open_workbook(
                    path,
                    formatting_info=1,
                    on_demand=True,
                    ragged_rows=True),
                os.path.split(path)[1]
                ) 
開發者ID:Scemoon,項目名稱:lpts,代碼行數:21,代碼來源:filter.py

示例2: __call__

# 需要導入模塊: import xlrd [as 別名]
# 或者: from xlrd import Book [as 別名]
def __call__(self, filter):
        """
        Once instantiated, a reader will be called and have the first
        filter in the chain passed to its :meth:`__call__` method.
        The implementation of this method
        should call the appropriate methods on the filter based on the
        cells found in the :class:`~xlrd.Book` objects returned from the
        :meth:`get_workbooks` method.
        """
        filter.start()
        for workbook,filename in self.get_workbooks():
            filter.workbook(workbook,filename)
            for sheet_x in range(workbook.nsheets):
                sheet = workbook.sheet_by_index(sheet_x)
                filter.sheet(sheet,sheet.name)
                for row_x in xrange(sheet.nrows):
                    filter.row(row_x,row_x)
                    for col_x in xrange(sheet.row_len(row_x)):
                        filter.cell(row_x,col_x,row_x,col_x)
                if workbook.on_demand:
                    workbook.unload_sheet(sheet_x)
        filter.finish() 
開發者ID:Scemoon,項目名稱:lpts,代碼行數:24,代碼來源:filter.py

示例3: __init__

# 需要導入模塊: import xlrd [as 別名]
# 或者: from xlrd import Book [as 別名]
def __init__(self, io, engine=None):
        if engine is None:
            engine = 'xlrd'
        if engine not in self._engines:
            raise ValueError("Unknown engine: {engine}".format(engine=engine))

        # could be a str, ExcelFile, Book, etc.
        self.io = io
        # Always a string
        self._io = _stringify_path(io)

        self._reader = self._engines[engine](self._io) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:14,代碼來源:excel.py

示例4: workbook

# 需要導入模塊: import xlrd [as 別名]
# 或者: from xlrd import Book [as 別名]
def workbook(self,rdbook,wtbook_name):
        """
        This method is called every time processing of a new
        workbook starts.

        :param rdbook: the :class:`~xlrd.Book` object from which the new workbook
                 should be created.

        :param wtbook_name: the name of the workbook into which content
                      should be written.
        """
        self.next.workbook(rdbook,wtbook_name) 
開發者ID:Scemoon,項目名稱:lpts,代碼行數:14,代碼來源:filter.py

示例5: __init__

# 需要導入模塊: import xlrd [as 別名]
# 或者: from xlrd import Book [as 別名]
def __init__(self, io, **kwds):

        err_msg = "Install xlrd >= 0.9.0 for Excel support"

        try:
            import xlrd
        except ImportError:
            raise ImportError(err_msg)
        else:
            ver = tuple(map(int, xlrd.__VERSION__.split(".")[:2]))
            if ver < (0, 9):  # pragma: no cover
                raise ImportError(err_msg +
                                  ". Current version " + xlrd.__VERSION__)

        # could be a str, ExcelFile, Book, etc.
        self.io = io
        # Always a string
        self._io = _stringify_path(io)

        engine = kwds.pop('engine', None)

        if engine is not None and engine != 'xlrd':
            raise ValueError("Unknown engine: {engine}".format(engine=engine))

        # If io is a url, want to keep the data as bytes so can't pass
        # to get_filepath_or_buffer()
        if _is_url(self._io):
            io = _urlopen(self._io)
        elif not isinstance(self.io, (ExcelFile, xlrd.Book)):
            io, _, _, _ = get_filepath_or_buffer(self._io)

        if engine == 'xlrd' and isinstance(io, xlrd.Book):
            self.book = io
        elif not isinstance(io, xlrd.Book) and hasattr(io, "read"):
            # N.B. xlrd.Book has a read attribute too
            if hasattr(io, 'seek'):
                try:
                    # GH 19779
                    io.seek(0)
                except UnsupportedOperation:
                    # HTTPResponse does not support seek()
                    # GH 20434
                    pass

            data = io.read()
            self.book = xlrd.open_workbook(file_contents=data)
        elif isinstance(self._io, compat.string_types):
            self.book = xlrd.open_workbook(self._io)
        else:
            raise ValueError('Must explicitly set engine if not passing in'
                             ' buffer or path for io.') 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:53,代碼來源:excel.py

示例6: __init__

# 需要導入模塊: import xlrd [as 別名]
# 或者: from xlrd import Book [as 別名]
def __init__(self, io, **kwds):

        err_msg = "Install xlrd >= 0.9.0 for Excel support"

        try:
            import xlrd
        except ImportError:
            raise ImportError(err_msg)
        else:
            ver = tuple(map(int, xlrd.__VERSION__.split(".")[:2]))
            if ver < (0, 9):  # pragma: no cover
                raise ImportError(err_msg +
                                  ". Current version " + xlrd.__VERSION__)

        # could be a str, ExcelFile, Book, etc.
        self.io = io
        # Always a string
        self._io = _stringify_path(io)

        engine = kwds.pop('engine', None)

        if engine is not None and engine != 'xlrd':
            raise ValueError("Unknown engine: {engine}".format(engine=engine))

        # If io is a url, want to keep the data as bytes so can't pass
        # to get_filepath_or_buffer()
        if _is_url(self._io):
            io = _urlopen(self._io)
        elif not isinstance(self.io, (ExcelFile, xlrd.Book)):
            io, _, _ = get_filepath_or_buffer(self._io)

        if engine == 'xlrd' and isinstance(io, xlrd.Book):
            self.book = io
        elif not isinstance(io, xlrd.Book) and hasattr(io, "read"):
            # N.B. xlrd.Book has a read attribute too
            data = io.read()
            self.book = xlrd.open_workbook(file_contents=data)
        elif isinstance(self._io, compat.string_types):
            self.book = xlrd.open_workbook(self._io)
        else:
            raise ValueError('Must explicitly set engine if not passing in'
                             ' buffer or path for io.') 
開發者ID:nccgroup,項目名稱:Splunking-Crime,代碼行數:44,代碼來源:excel.py


注:本文中的xlrd.Book方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。