相关疑难解决方法(0)

错误:不支持的格式或损坏的文件:预期的BOF记录

我试图打开一个xlsx文件,只打印它的内容.我一直遇到这个错误:

import xlrd
book = xlrd.open_workbook("file.xlsx")
print "The number of worksheets is", book.nsheets
print "Worksheet name(s):", book.sheet_names()
print

sh = book.sheet_by_index(0)

print sh.name, sh.nrows, sh.ncols
print

print "Cell D30 is", sh.cell_value(rowx=29, colx=3)
print

for rx in range(5):
    print sh.row(rx)
    print
Run Code Online (Sandbox Code Playgroud)

它打印出这个错误

raise XLRDError('Unsupported format, or corrupt file: ' + msg)
xlrd.biffh.XLRDError: Unsupported format, or corrupt file: Expected BOF record; found    '\xff\xfeT\x00i\x00m\x00'
Run Code Online (Sandbox Code Playgroud)

谢谢

python csv excel xlrd

12
推荐指数
4
解决办法
4万
查看次数

ImportError:无法在python中导入名称COMError

我想用以下代码将docx文件转换为pdf

import sys
import os
import comtypes.client


wdFormatPDF = 17

in_file = os.path.abspath(sys.argv[1])
out_file = os.path.abspath(sys.argv[2])

word = comtypes.client.CreateObject('Word.Application')
doc = word.Documents.Open(in_file)
doc.SaveAs(out_file, FileFormat=wdFormatPDF)
doc.Close()
word.Quit()
Run Code Online (Sandbox Code Playgroud)

这是一个错误

ImportError: cannot import name COMError
Run Code Online (Sandbox Code Playgroud)

我已经安装了comtypes包.

我是python的新手,我无法弄清楚如何解决这个问题.

[编辑]

堆栈跟踪

Traceback (most recent call last):
  File "converttopdf.py", line 3, in <module>
    import comtypes.client
  File "/usr/local/lib/python2.7/dist-packages/comtypes-1.1.2-py2.7.egg/comtypes/__init__.py", line 23, in <module>
    from _ctypes import COMError
ImportError: cannot import name COMError
Run Code Online (Sandbox Code Playgroud)

python pdf-generation python-2.7

4
推荐指数
1
解决办法
4477
查看次数

标签 统计

python ×2

csv ×1

excel ×1

pdf-generation ×1

python-2.7 ×1

xlrd ×1