原文:
https://blog.csdn.net/qq_27017791/article/details/113849053
Excel格式
效果
代码
import quopri
import xlrd
#111.xlsx为需要处理的表格(姓名+电话)
file2='111.xlsx'
#123.vcf 为处理后生成的文件
file1=open('123.vcf','w+',encoding='utf-8')
workbook=xlrd.open_workbook(file2)
sheet=workbook.sheet_by_index(0)
n_of_rows=sheet.nrows
print(n_of_rows)
for i in range(n_of_rows):
file1.write('BEGIN:VCARD
')
file1.write('VERSION:2.1
')
name=sheet.cell(i,0).value
name1='N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;'+str(quopri.decodestring(name.encode()))[2:-1].replace('\x','=').upper()+';;;
'
name2='FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;'+str(quopri.decodestring(name.encode()))[2:-1].replace('\x','=').upper()+'
'
file1.write(name1)
file1.write(name2)
print('TEL;CELL:'+str(int(sheet.cell(i,1).value))+'
')
file1.write('TEL;CELL:'+str(int(sheet.cell(i,1).value))+'
')
file1.write('END:VCARD
')
file1.close()