python學習,excel操做之xlrd模塊經常使用操做

 1 import xlrd
 2 
 3 ##工做表##
 4 #打開excel
 5 f = xlrd.open_workbook("test.xlsx")
 6 file = f.sheet_by_name("test")
 7 #獲取sheet對象的列表
 8 print(f.sheets())
 9 #經過索引獲取sheet對象
10 print(f.sheet_by_index(0))
11 #經過名稱獲取sheet對象
12 print(f.sheet_by_name("test"))
13 #獲取sheet列表
14 print(f.sheet_names())
15 #判斷sheet是否存在
16 print(f.sheet_loaded("test"))
17 
18 ##數據行##
19 #獲取數據有效行數
20 print(file.nrows)
21 #獲取指定行數據
22 print(file.row(0))
23 #獲取指定行數據
24 print(file.row_slice(0))
25 #獲取指定行數據類型
26 print(file.row_types(0))
27 #獲取指定行數據
28 print(file.row_values(0))
29 #獲取指定行數據長度
30 print(file.row_len(0))
31 
32 ##數據列##
33 #獲取列長度
34 print(file.ncols)
35 #返回該列的對象數據列表
36 print(file.col_slice(2))
37 #返回該列的對象數據列表
38 print(file.col(2))
39 #返回該列的類型數據列表
40 print(file.col_types(2))
41 #返回該列的值數據列表
42 print(file.col_values(2))
43 
44 ##單元格##
45 #獲取單元格數據
46 print(file.cell(0,2))
47 #獲取單元格數據
48 print(file.cell(0,2).value)
49 #獲取單元格數據類型
50 print(file.cell(0,2).ctype)
51 #獲取單元格數據類型
52 print(file.cell_type(0,2))
53 #獲取單元格數據
54 print(file.cell_value(0,2))
相關文章
相關標籤/搜索