-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
48 lines (39 loc) · 1.27 KB
/
main.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
37
38
39
40
41
42
43
44
45
46
47
48
# Creator: Reenphy George
# Date : 26th December
# Title: Sheets to VCF with batch rename
from openpyxl import load_workbook
from openpyxl.utils import get_column_letter
import os
a=(input("Enter the name of file : "))
a=a+".xlsx"
wb = load_workbook(a)
ws = wb.active
# function to group rename
def rename():
str_append = input("Enter the string to be appended: ")
name = 1
while (ws[get_column_letter(name) + '1'].value).lower() != 'name':
name += 1
row = ws.max_row
for i in range(2,row+1):
exl = ws[get_column_letter(name) + str(i)].value
exl = exl + " " + str_append
ws[get_column_letter(name) + str(i)].value = exl
wb.save(a)
print("Successfully Renamed ")
return name
# function to create vcf
def vcf(name):
contact = 1
while (ws[get_column_letter(contact) + '1'].value).lower() != 'phone':
contact += 1
row = ws.max_row
f = open('temp.txt' , 'a')
for i in range(2,row+1):
fn = str(ws[get_column_letter(name) + str(i)].value)
tel = str(ws[get_column_letter(contact) + str(i)].value)
f.write("BEGIN:VCARD\nFN:"+fn+"\nTEL:"+tel+"\nEND:VCARD\n\n")
os.renames('temp.txt', 'contact.vcf')
print("VCF Exported Succesfully")
name = rename()
vcf(name)