1
我想從數百個SAS生成的.xls文件中提取選項卡。我嘗試了以下方法,但沒有運氣。我的版本xlrd
是0.9.2。Python讀取SAS生成的XML類型.xls文件
import xlrd
book = xlrd.open_workbook('out_1.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">
你介意給我如何提出了一些建議:
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
文件解析這些文件?謝謝!