python xlrd读取Excel文件

 1 import xlrd
 2 
 3 #打开excel文件
 4 book = xlrd.open_workbook('salary.xls')
 5 
 6 #打印每个工作表的名称
 7 for sheet in book.sheets():
 8     print(sheet.name)
 9 
10 #选择工作表
11 sheet = book.sheet_by_name('管理公司')
12 
13 #打印工作表的总行数
14 print(sheet.nrows)
15 
16 #遍历每一行内容
17 for i in range(sheet.nrows):
18     print(sheet.row_values(i))
19 
20 #遍历每一个元素
21 for i in range(sheet.nrows):
22     row = sheet.row_values(i)
23     for cell in row:
24         print(cell)

猜你喜欢

转载自www.cnblogs.com/sineik/p/9061948.html