python办公入门4:xlrd操作excel行

python办公入门4:xlrd操作excel行[Python基础]

操作excel行

 1 #通过索引获取操作行
 2 sheet=data.sheet_by_index(0)
 3 #获取当前sheet下的有效行数
 4 print(sheet.nrows)
 5 #获取某一行的具体数据,是由该行单元格对象组成的列表,前面的表示数据类型
 6 print(sheet.row(0))
 7 #获取某一行的数据类型
 8 print(sheet.row_types(0))
 9 #获取某一行中的一格的值对
10 print(sheet.row(3)[3])
11 #仅仅获取单元格的的值
12 print(sheet.row(3)[3].value)
13 #得到一行的值
14 print(sheet.row_values(3))
15 #得到某一行的长度
16 print(sheet.row_len(3))

运行结果

1 13
2 [text:"列1", text:"代码", text:"成本", text:"总金额", text:"平台", text:"盈利", text:"所属类别"]
3 array("B", [1, 1, 1, 1, 1, 1, 1])
4 number:16866.86
5 16866.86
6 ["微信零钱通", "零钱", 16836.48, 16866.86, "微信零钱通", 30.38000000000102, "零钱"]
7 7