我正在尝试从数百个 SAS 生成的 .xls 文件中提取选项卡。我没有运气就尝试了以下方法。我的版本xlrd
是 0.9.2。
import xlrd
book = xlrd.open_workbook('out_1.xls')
错误信息是:
Traceback (most recent call last):[Finished in 0.2s with exit code 1]
File "I:\Dropbox\Sas data\sacwin\test.py", line 3, in <module>
book = xlrd.open_workbook('out_1.xls') # Open an .xls file
File "C:\Python27\lib\site-packages\xlrd\__init__.py", line 435, in open_workbook
ragged_rows=ragged_rows,
File "C:\Python27\lib\site-packages\xlrd\book.py", line 91, in open_workbook_xls
biff_version = bk.getbof(XL_WORKBOOK_GLOBALS)
File "C:\Python27\lib\site-packages\xlrd\book.py", line 1258, in getbof
bof_error('Expected BOF record; found %r' % self.mem[savpos:savpos+8])
File "C:\Python27\lib\site-packages\xlrd\book.py", line 1252, in bof_error
raise XLRDError('Unsupported format, or corrupt file: ' + msg)
xlrd.biffh.XLRDError: Unsupported format, or corrupt file: Expected BOF record; found '<?xml ve'
.xls
在编辑器中打开文件后,标题如下所示:
<?xml version="1.0" encoding="windows-1252"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office">
你介意给我一些关于如何解析这些文件的建议吗?谢谢!