xlrd python37不兼容_Python之xlrd读Excel文件问题解决 (python xlrd unsupported format, or corrupt file.)...

最近使用PyChram创建xls文件导致不能读取写入该文件

解决:在桌面上手动创建Excel文件即可解决。

import xlrd

import xlutils.copy

#打开一个workbook

filename = r'H:\Timed_scheduling\data.xls'

rb = xlrd.open_workbook(filename, encoding_override="utf-8")

wb = xlutils.copy.copy(rb)

#获取sheet对象,通过sheet_by_index()获取的sheet对象没有write()方法

ws = wb.get_sheet(0)

#写入数据

ws.write(1, 1, 'GG')

#添加sheet页

wb.add_sheet('sheetnnn2',cell_overwrite_ok=True)

#利用保存时同名覆盖达到修改excel文件的目的,注意未被修改的内容保持不变

wb.save(filename)

问题一

引发xlrderrror(“文件大小为0字节”)

xlrd.biffh.xlrd错误:文件大小为0字节

The error:

Traceback (most recent call last):

File “H://Timed_scheduling/testcase.py”, line 21, in

rb = xlrd.open_workbook(filename, encoding_override=“utf-8”)

File “C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\xlrd_init_.py”, line 157, in open_workbook

ragged_rows=ragged_rows,

File “C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\xlrd\book.py”, line 88, in open_workbook_xls

ragged_rows=ragged_rows,

File “C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\xlrd\book.py”, line 616, in biff2_8_load

raise XLRDError(“File size is 0 bytes”)

xlrd.biffh.XLRDError: File size is 0 bytes

问题二

raise xlrderor(‘不支持的格式,或损坏的文件:’+msg)

xlrd.biffh.xlrderrror:不支持的格式,或损坏的文件:需要的BOF记录;找到B’11\r\n’

The error:

Traceback (most recent call last):

File “H:/Timed_scheduling/testcase.py”, line 21, in

rb = xlrd.open_workbook(filename, encoding_override=“utf-8”)

File “C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\xlrd_init_.py”, line 157, in open_workbook

ragged_rows=ragged_rows,

File “C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\xlrd\book.py”, line 92, in open_workbook_xls

biff_version = bk.getbof(XL_WORKBOOK_GLOBALS)

File “C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\xlrd\book.py”, line 1278, in getbof

bof_error(‘Expected BOF record; found %r’ % self.mem[savpos:savpos+8])

File “C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\xlrd\book.py”, line 1272, in bof_error

raise XLRDError(‘Unsupported format, or corrupt file: ’ + msg)

xlrd.biffh.XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b’11\r\n’

解决方法

在桌面上手动创建Excel文件即可解决!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值