from xlrd import *
book = open_workbook("File_1.xls")
#sheet = book.sheets()[0]
#book.sheets() returns a list of sheet objects... alternatively...
#sheet = book.sheet_by_name("qqqq") #we can pull by name
sheet = book.sheet_by_index(0) #or by the index it has in excel's sheet collection
r = sheet.row(0) #returns all the CELLS of row 0,
c = sheet.col_values(0) #returns all the VALUES of row 0,
for i in xrange(sheet.nrows):
print sheet.row_values(5)
我正在读取桌面中的文件,但是当我运行用 python 编写的脚本时,它会出错
Traceback (most recent call last):
File "C:\Python26\ReadXLS.py", line 6, in <module>
book = open_workbook("File_1.xls")
File "C:\Python26\Lib\site-packages\xlrd\__init__.py", line 449, in open_workbook
ragged_rows=ragged_rows,
File "C:\Python26\Lib\site-packages\xlrd\__init__.py", line 941, in biff2_8_load
f = open(filename, open_mode)
IOError: [Errno 2] No such file or directory: 'File_1.xls'