-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathxlrdTest.py
37 lines (28 loc) · 856 Bytes
/
xlrdTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import xlrd
print (xlrd.__file__)
#----------------------------------------------------------------------
def open_file(path):
"""
Open and read an Excel file
"""
book = xlrd.open_workbook(path)
# print number of sheets
print (book.nsheets)
# print sheet names
print (book.sheet_names())
# get the first worksheet
first_sheet = book.sheet_by_index(0)
# read a row
print (first_sheet.row_values(0))
# read a cell
cell = first_sheet.cell(0,0)
print (cell)
print (cell.value)
# read a row slice
print (first_sheet.row_slice(rowx=0,
start_colx=0,
end_colx=2))
#----------------------------------------------------------------------
if __name__ == "__main__":
path = "worksheet1.xlsx"
open_file(path)