-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxls.py
More file actions
62 lines (54 loc) · 1.43 KB
/
xls.py
File metadata and controls
62 lines (54 loc) · 1.43 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#############################################################
# file: xls.py
# brief: use xlrd process office excel files
# author: xiyang
# date: 12/04/04
# changleLists:
#
#############################################################
#! /usr/bin/env python
#coding=utf-8
import xlrd
import os,os.path
#define the directory
DATA_PATH = r'D:\test'
files = os.listdir(DATA_PATH)
data = {}
def extraRecord(filepath):
bk = xlrd.open_workbook(filepath)
shxrange = range(bk.nsheets)
try:
sh = bk.sheet_by_name('Sheet1')
except:
print "no sheet in %s named Sheet1" % fname
return None
nrows = sh.nrows
ncols = sh.ncols
for i in range(3,nrows):
row_data = sh.row_values(i)
if row_data[2]:
l = []
name = row_data[1]
#sdut
l.append(row_data[2])
#pku
l.append(row_data[4])
#hdu
l.append(row_data[6])
#bauu
l.append(row_data[8])
#zju
l.append(row_data[10])
#hru
l.append(row_data[12])
data[name] = l
print "->"+name+":",data[name]
# traverse
for file in files:
if os.path.isfile:
#get the file's ext
temp = os.path.splitext(file)
ext = temp[1]
if ext == '.xls':
#print os.path.join(DATA_PATH,file)
extraRecord(os.path.join(DATA_PATH,file))