报错代码如下:

filePath='test.xls'
data=pd.read_excel(filePath)
print(data.head())

报错内容如下:

Traceback (most recent call last):
File "e:/PyCharm/Demo/TestFileDirectory/test.py", line 18, in <module>
data=pd.read_excel(filePath,data__only=True)
File "D:\Program Files\Python37\lib\site-packages\pandas\util\_decorators.py", line 208, in wrapper
return func(*args, **kwargs)
File "D:\Program Files\Python37\lib\site-packages\pandas\io\excel\_base.py", line 310, in read_excel
io = ExcelFile(io, engine=engine)
File "D:\Program Files\Python37\lib\site-packages\pandas\io\excel\_base.py", line 819, in __init__
self._reader = self._engines[engine](self._io)
File "D:\Program Files\Python37\lib\site-packages\pandas\io\excel\_xlrd.py", line 21, in __init__
super().__init__(filepath_or_buffer)
File "D:\Program Files\Python37\lib\site-packages\pandas\io\excel\_base.py", line 359, in __init__
self.book = self.load_workbook(filepath_or_buffer)
File "D:\Program Files\Python37\lib\site-packages\pandas\io\excel\_xlrd.py", line 36, in load_workbook
return open_workbook(filepath_or_buffer)
File "D:\Program Files\Python37\lib\site-packages\xlrd\__init__.py", line 157, in open_workbook
ragged_rows=ragged_rows,
File "D:\Program Files\Python37\lib\site-packages\xlrd\book.py", line 88, in open_workbook_xls
ragged_rows=ragged_rows,
File "D:\Program Files\Python37\lib\site-packages\xlrd\book.py", line 636, in biff2_8_load
cd.locate_named_stream(UNICODE_LITERAL(qname))
File "D:\Program Files\Python37\lib\site-packages\xlrd\compdoc.py", line 399, in locate_named_stream
d.tot_size, qname, d.DID+6)
File "D:\Program Files\Python37\lib\site-packages\xlrd\compdoc.py", line 434, in _locate_stream
% (qname, found_limit * sec_size)
xlrd.compdoc.CompDocError: Workbook: size exceeds expected 17920 bytes; corrupt?

已试用但未成功方案:

import xlrd
import pandas as pd #方式一:
data=pd.read_excel(filePath)
print(data.head()) #方式二:
x1 = xlrd.open_workbook(filePath)
mySheet = x1.sheets()[0]
nrows = mySheet.nrows
print("row num:", nrows) #方式三:
f = open(filePath, 'rb')
lines = f.readlines()
for line in lines:
line = line.decode('gbk').encode('utf8')
print (line)

最后的解决方案如下:

from win32com.client import Dispatch

filePath='test.xls'
xl = Dispatch('Excel.Application')
wb = xl.Workbooks.Open(filePath)
ws = wb.Worksheets(1)
info = ws.UsedRange
rows = info.Rows.Count
print (rows)

[已解决]报错:xlrd.compdoc.CompDocError: Workbook: size exceeds expected 17920 bytes; corrupt?的更多相关文章

  1. [已解决]报错: Error response from daemon: conflict

    报错内容: Error response from daemon: conflict: unable to delete f5b6ef70d79b (must be forced) - image i ...

  2. [已解决]报错: Windows下Redis服务无法启动,错误 1067 进程意外终止解决方案

    启动redis时出现的报错内容: 解决方法: 找到登录状态 如果是网络服务,直接双击此服务,修改为本地系统服务即可启动!

  3. [已解决]报错: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Users/mac/Ana

    报错代码: pip3 install gerapy 报错内容: Could not install packages due to an EnvironmentError: [Errno 13] Pe ...

  4. [已解决]报错: Creating Server TCP listening socket 127.0.0.1:6379: bind: No error

    问题: windows下安装Redis第一次启动报错: [2368] 21 Apr 02:57:05.611 # Creating Server TCP listening socket 127.0. ...

  5. [已解决]报错JSONDecodeError

    报错: 解决:

  6. [已解决]报错:ValueError: Expected 2D array, got scalar array instead

    报错代码: new_x = 84610 pre_y = model.predict(new_x) print(pre_y) 报错结果: ValueError: Expected 2D array, g ...

  7. [已解决]报错:have mixed types. Specify dtype option on import or set low_memory=False

    报错代码: import pandas as pd pd1 = pd.read_csv('D:/python34/program/wx_chat_single/qq_single.csv') 报错内容 ...

  8. [已解决]报错Could not install packages due to an EnvironmentError

    安装OpenCV过程中出现错误 代码: pip-conda install -i https://pypi.douban.com/simple/ opencv-python 报错内容如下: Could ...

  9. [已解决]报错UnicodeDecodeError

    输出报错: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc4 in position 220: in 解决方案:将编码方式utf-8 修 ...

随机推荐

  1. django创建web页面

    https://blog.csdn.net/ImagineCode/article/details/54586326 https://blog.csdn.net/qq_29186489/article ...

  2. easyUI学习笔记一

    1.引用js文件 <script type="text/javascript" src = jquery-easyui/jquery.min.js> </scri ...

  3. Codefores 507B Amr and Pins

    B. Amr and Pins time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  4. matploylib之热力图

    刚学我也不熟,做个笔记吧 # coding:utf-8 import numpy as np import matplotlib.pyplot as plt dx = 0.01 dy = 0.01 # ...

  5. 拓展练习--find查找、打包压缩、服务器、磁盘挂载

    目录 find查找.打包压缩 服务器部分 磁盘挂载及单用户模式 find查找.打包压缩 1.超级用户(管理员用户)提示符是_#,普通用户提示符是$_. 2.如何快速返回上一次所在的目录? cd - 3 ...

  6. 1、selenium 8大元素定位方式

    元素定位方式: id name css class_name tag_name partial_link link_text : driver. find_element_by_link_text(& ...

  7. 【leetcode】1004. Max Consecutive Ones III

    题目如下: Given an array A of 0s and 1s, we may change up to K values from 0 to 1. Return the length of ...

  8. Ubuntu下的安装notepad++

    Ubuntu下的安装方法: sudo add-apt-repository ppa:notepadqq-team/notepadqq sudo apt-get update sudo apt-get ...

  9. 硬币问题 (dp,多重背包的二分优化)

    题目描述 给你n种硬币,知道每种的面值Ai和每种的数量Ci.问能凑出多少种不大于m的面值. 输入 有多组数据,每一组第一行有两个整数 n(1≤n≤100)和m(m≤100000),第二行有2n个整数, ...

  10. Integer之常用方法

    public static int parseInt(String s, int radix) throws NumberFormatException {} // radix进制 s 换成 10进制 ...