电商 微信 批量添加客户2 python版

原文:
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\n')
    file1.write('VERSION:2.1\n')
    name=sheet.cell(i,0).value
    name1='N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;'+str(quopri.decodestring(name.encode()))[2:-1].replace('\\x','=').upper()+';;;\n'
    name2='FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;'+str(quopri.decodestring(name.encode()))[2:-1].replace('\\x','=').upper()+'\n'
    file1.write(name1)
    file1.write(name2)
    print('TEL;CELL:'+str(int(sheet.cell(i,1).value))+'\n')
    file1.write('TEL;CELL:'+str(int(sheet.cell(i,1).value))+'\n')
    file1.write('END:VCARD\n')
 
file1.close()


posted @ 2021-07-14 10:03  古兴越  阅读(102)  评论(0编辑  收藏  举报