-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexcel2rcard.py
More file actions
executable file
·68 lines (42 loc) · 1.52 KB
/
excel2rcard.py
File metadata and controls
executable file
·68 lines (42 loc) · 1.52 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
63
64
65
66
67
68
import xlrd
import sys, getopt
opts, args = getopt.getopt(sys.argv[1:], "hi:o:")
input_file=""
output_file=""
initflag = 0;
for op, value in opts:
if op == "-i":
initflag = 1;
input_file = value
elif op == "-o":
initflag = 1;
output_file = value
elif op == "-h":
print("-i inputfile -o outputfile")
sys.exit()
if initflag == 0 :
print("-i inputfile -o outputfile")
sys.exit()
data = xlrd.open_workbook(input_file);
table = data.sheets()[0];
nrows = table.nrows
ncols = table.ncols
print("nrows", nrows);
startdatarow = (int)(input("通信录数据起始行(始于0): "))
enddatarow = (int)(input("通信录数据结束行(始于0): "))
namecol = (int)(input("名字所在列(始于0): "))
cellcol = (int)(input("电话所在列(始于0):"))
f = open(output_file, 'w', encoding='utf-8')
for i in range(startdatarow , enddatarow):
ctype = table.cell(i, cellcol).ctype
cell = table.cell(i, cellcol).value
if ctype == 2 and cell % 1 == 0.0: # ctype为2且为浮点
cell = int(cell) # 浮点转成整型
cell = str(cell) # 转成整型后再转成字符串,如果想要整型就去掉该行
f.write("BEGIN:VCARD\n");
f.write("VERSION:3.0\n");
f.write("FN:" + table.cell(i,namecol).value + "\n");
f.write("TEL;TYPE=CELL:" + cell + "\n");
f.write("ORG;CHARSET=utf-8:南京能云电力\n");
f.write("END:VCARD\n");
f.close();