-
Notifications
You must be signed in to change notification settings - Fork 1
/
SimpleExcelToVcard.py
36 lines (31 loc) · 1.36 KB
/
SimpleExcelToVcard.py
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
import xlrd
import pandas as pd
import os
#file=os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop','Vcard','Contacts.xlsx') #If your excel file not in same directory with python file u can use it
file= 'Contacts.xlsx' #If your excel file in same directory with python file u can use it
excelfile= pd.ExcelFile(file)
column = excelfile.parse('Workers')
s = ""
begin = "BEGIN:VCARD\nVERSION:2.1"
for i in range(len(column)):
fName=""
sName=""
secMail=""
if(str(column["Phone"][i])!="nan"):
if(str(column["Name"][i])!="nan"):
fName=str(column["Name"][i])
if(str(column["Surname"][i])!="nan"):
sName=str(column["Surname"][i])
#s+=begin+"\nN:;"+str(column["Name"][i]).split(".")[0]+";;;\nFN:"+str(column["Surname"][i]).split(".")[0]+"\nTEL;CELL:+"+str(column["Phone"][i]).split(".")[0]+"\nEND:VCARD\n"
secN="\nN:"+ sName + ";" + fName + ";;;"
secFN="\nFN:" + fName +" "+ sName
secPhone="\nTEL;CELL:+"+str(column["Phone"][i]).split(".")[0]
if("Mail" in column.columns.values):
secMail=""
if(str(column["Mail"][i]) != "nan"):
secMail="\nEMAIL;HOME:"+str(column["Mail"][i])
s+=begin+secN + secFN +secPhone + secMail +"\nEND:VCARD\n"
text_file = open("Exported.vcf", "w")
text_file.write(s)
text_file.close()
print("Completed!")