[python3]xlrd不支持Excel xlsx文件类型

发布于:2025-02-11 ⋅ 阅读:(42) ⋅ 点赞:(0)

https://xlrd.readthedocs.io/en/latest/

xlrd is a library for reading data and formatting information from Excel files in the historical .xls format.

解决办法:指定支持的版本1.2.0,pip3 install xlrd==1.20

pip3 install xlrd==1.2.0
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/
Collecting xlrd==1.2.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b0/16/63576a1a001752e34bf8ea62e367997530dc553b689356b9879339cf45a4/xlrd-1.2.0-py2.py3-none-any.whl (103 kB)
Installing collected packages: xlrd
  Attempting uninstall: xlrd
    Found existing installation: xlrd 2.0.1
    Uninstalling xlrd-2.0.1:
      Successfully uninstalled xlrd-2.0.1
Successfully installed xlrd-1.2.0

错误信息:

    data = xlrd.open_workbook(file_name)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

filename = '/Users/apple/opt/git_huaun/test/huaun-train-autotest/src/testcase/aikg/api/request.xlsx'
logfile = <_io.TextIOWrapper name='<stdout>' mode='w' 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


网站公告

今日签到

点亮在社区的每一天
去签到