Python-xlrd包book.py里的class Book类的使用

关于Class Book(BaseObject):


意思就是你不应该自己实例化这个类。你可以在调用函数 xlrd.open_workbook时返回这个对象

自己实例化是这样:

book = Book()

然而这个类不应该自己实例化,而是在调用xlrd.open_workbook时会返回这个类

举个例子:


第二句代码book = xlrd.open_workbook(bookname)就是调用了xlrd.open_workbook()这个函数,然后返回了一个Book对象

之后我们要调用xlrd包book.py里面的

Book类里面的函数,都可以用这个第二句代码的book来调用了。

即这样:

比如我们要调用Book类里面的这个函数


就可以通过语句

book.sheet_by_index( 0 )来调用

#这里0是一个参数,随你输入




报错了: FAILED [100%] test_len.py:9 (TestWms.test_02) self = <case.test_len.TestWms object at 0x000002902917B2B0> def test_02(self): > datas = xfile.read(r"C:\Users\shuohan\Desktop\gaoliu-1\仓库删除模块接口用例.xlsx").excel_to_dict(sheet=1) test_len.py:11: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ..\..\myvenv\lib\site-packages\xToolkit\xfile\dispose\dispose.py:67: in excel_to_dict workbook = xlrd.open_workbook(excel_file) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ filename = 'C:\\Users\\shuohan\\Desktop\\gaoliu-1\\仓库删除模块接口用例.xlsx' logfile = <_io.TextIOWrapper name='<tempfile._TemporaryFileWrapper object at 0x00000290000E2940>' mode='r+' encoding='utf-8'> verbosity = 0, use_mmap = True, file_contents = None, encoding_override = None formatting_info = False, on_demand = False, ragged_rows = False ignore_workbook_corruption = False def open_workbook(filename=None, logfile=sys.stdout, verbosity=0, use_mmap=True, file_contents=None, encoding_override=None, formatting_info=False, on_demand=False, ragged_rows=False, ignore_workbook_corruption=False ): """ Open a spreadsheet file for data extraction. :param filename: The path to the spreadsheet file to be opened. :param logfile: An open file to which messages and diagnostics are written. :param verbosity: Increases the volume of trace material written to the logfile. :param use_mmap: Whether to use the mmap module is determined heuristically. Use this arg to override the result. Current heuristic: mmap is used if it exists. :param file_contents: A string or an :class:`mmap.mmap` object or some other behave-alike object. If ``file_contents`` is supplied, ``filename`` will not be used, except (possibly) in messages. :param encoding_override: Used to overcome missing or bad codepage information in older-version files. See :doc:`unicode`. :param formatting_info: The default is ``False``, which saves memory. In this case, "Blank" cells, which are those with their own formatting information but no data, are treated as empty by ignoring the file's ``BLANK`` and ``MULBLANK`` records. This cuts off any bottom or right "margin" of rows of empty or blank cells. Only :meth:`~xlrd.sheet.Sheet.cell_value` and :meth:`~xlrd.sheet.Sheet.cell_type` are available. When ``True``, formatting information will be read from the spreadsheet file. This provides all cells, including empty and blank cells. Formatting information is available for each cell. Note that this will raise a NotImplementedError when used with an xlsx file. :param on_demand: Governs whether sheets are all loaded initially or when demanded by the caller. See :doc:`on_demand`. :param ragged_rows: The default of ``False`` means all rows are padded out with empty cells so that all rows have the same size as found in :attr:`~xlrd.sheet.Sheet.ncols`. ``True`` means that there are no empty cells at the ends of rows. This can result in substantial memory savings if rows are of widely varying sizes. See also the :meth:`~xlrd.sheet.Sheet.row_len` method. :param ignore_workbook_corruption: This option allows to read corrupted workbooks. When ``False`` you may face CompDocError: Workbook corruption. When ``True`` that exception will be ignored. :returns: An instance of the :class:`~xlrd.book.Book` class. """ file_format = inspect_format(filename, file_contents) # We have to let unknown file formats pass through here, as some ancient # files that xlrd can parse don't start with the expected signature. if file_format and file_format != 'xls': > raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+'; not supported') E xlrd.biffh.XLRDError: Excel xlsx file; not supported ..\..\myvenv\lib\site-packages\xlrd\__init__.py:170: XLRDError
最新发布
07-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值