如何修复“XLRDError:ZIP 文件内容不是已知类型的工作簿”

Posted

技术标签:

【中文标题】如何修复“XLRDError:ZIP 文件内容不是已知类型的工作簿”【英文标题】:How to fix "XLRDError: ZIP file contents not a known type of workbook" 【发布时间】:2019-10-29 18:34:21 【问题描述】:

我写了这段代码,它说这样的错误帮助我解决这个问题

我已经安装了xlrd 并再次使用pip install xlrd

import numpy as np import pandas as pd import os datas=pd.read_excel('transactions.xlsx') datas

错误显示如下

XLRDError                                 Traceback (most recent call last)
<ipython-input-61-f7361e459a83> in <module>
      2 import pandas as pd
      3 import os
----> 4 datas=pd.read_excel('transactions.xlsx')
      5 datas

~\Anaconda3\lib\site-packages\pandas\util\_decorators.py in wrapper(*args, **kwargs)
    186                 else:
    187                     kwargs[new_arg_name] = new_arg_value
--> 188             return func(*args, **kwargs)
    189         return wrapper
    190     return _deprecate_kwarg

~\Anaconda3\lib\site-packages\pandas\util\_decorators.py in wrapper(*args, **kwargs)
    186                 else:
    187                     kwargs[new_arg_name] = new_arg_value
--> 188             return func(*args, **kwargs)
    189         return wrapper
    190     return _deprecate_kwarg

~\Anaconda3\lib\site-packages\pandas\io\excel.py in read_excel(io, sheet_name, header, names, index_col, parse_cols, usecols, squeeze, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, keep_default_na, verbose, parse_dates, date_parser, thousands, comment, skip_footer, skipfooter, convert_float, mangle_dupe_cols, **kwds)
    348 
    349     if not isinstance(io, ExcelFile):
--> 350         io = ExcelFile(io, engine=engine)
    351 
    352     return io.parse(

~\Anaconda3\lib\site-packages\pandas\io\excel.py in __init__(self, io, engine)
    651         self._io = _stringify_path(io)
    652 
--> 653         self._reader = self._engines[engine](self._io)
    654 
    655     def __fspath__(self):

~\Anaconda3\lib\site-packages\pandas\io\excel.py in __init__(self, filepath_or_buffer)
    422             self.book = xlrd.open_workbook(file_contents=data)
    423         elif isinstance(filepath_or_buffer, compat.string_types):
--> 424             self.book = xlrd.open_workbook(filepath_or_buffer)
    425         else:
    426             raise ValueError('Must explicitly set engine if not passing in'

~\Anaconda3\lib\site-packages\xlrd\__init__.py in open_workbook(filename, logfile, verbosity, use_mmap, file_contents, encoding_override, formatting_info, on_demand, ragged_rows)
    143         if 'content.xml' in component_names:
    144             raise XLRDError('Openoffice.org ODS file; not supported')
--> 145         raise XLRDError('ZIP file contents not a known type of workbook')
    146 
    147     from . import book

XLRDError: ZIP file contents not a known type of workbook

【问题讨论】:

您是否尝试加载任何其他具有相同扩展名的文件?这个文件好像有问题。 谢谢@Mikku 我没试过它有效:) 很高兴它成功了 :) .. 接受下面的答案。 【参考方案1】:

为面临相同错误的用户提供答案:

import numpy as np
import pandas as pd
import os
datas=pd.read_excel('transactions.xlsx')
datas

这应该可以,除非 Excel 文件有问题。尝试使用具有相同扩展名的其他文件。

【讨论】:

以上是关于如何修复“XLRDError:ZIP 文件内容不是已知类型的工作簿”的主要内容,如果未能解决你的问题,请参考以下文章

如何修复drv?

如何修复漏洞

如何修复WMI

PHP网站漏洞怎么修复 如何修补网站程序代码漏洞

如何修复这些漏洞? (npm audit fix 无法修复这些漏洞)

如何修复AppScan漏洞