通訊錄自動匯入 txt格式轉vcf格式

2021-10-01 20:18:17 字數 1394 閱讀 9322

新員工入職,如何將新的通訊錄匯入到員工手機,乙個個匯入太麻煩。vcf格式的檔案可以自動匯入,下面通過**將txt檔案的格式轉為vcf檔案格式。

txt檔案格式:

張三    13636508384

李四 12784378759

vcf 檔案格式:

begin:vcard

fn:張三

tel;type=cell;type=voice;type=pref:13636508384

end:vcard

begin:vcard

fn:李四

tel;type=cell;type=voice;type=pref:12784378759

end:vcard

可以看到vcf格式的檔案很有規則性,每個使用者及手機號乙個單元。(注:vcf檔案可以匯入的不僅僅是手機號可以是公司、部門崗位等多種資訊,在此只是匯入了手機號,如果想匯入其它資訊可以自己配置vcf檔案),下面是轉換**:

def txt_to_vcf(src_file):

"""該函式將txt檔案儲存成vcf檔案

:param src_file: 原始txt檔案

:return:

"""if os.path.exists(src_file):

# 讀取txt檔案

with open(src_file, "r", encoding="utf-8") as fs:

name_tel_list = fs.readlines()

"使用者名稱和手機號tab隔開"

name_list, tel_list = [x.split("\t")[0] for x in name_tel_list],

[x.split("\t")[1] for x in name_tel_list]

# 建立vcf檔案並寫入資料(當前目錄建立)

dstfile = src_file.split(".")[0] + ".vcf"

with open(dstfile, "w", encoding="utf-8") as fd:

for i in range(len(name_list)):

fd.write("begin:vcard\n")

fd.write("fn:" + name_list[i] + "\n")

fd.write("tel;type=cell;type=voice;type=pref:" + tel_list[i])

if i == len(name_list) - 1: fd.write("\n")

fd.write("end:vcard" + "\n")

else:

print("輸入txt檔案路徑報錯...")

VC個人通訊錄系統

資料庫連線字串為 bstr t strconn t provider microsoft.jet.oledb.4.0 data source stdmgr.mdb jet oledb database password studentmgr 這是我大二時學習vc寫的乙個小作品,有興趣的童鞋不妨拿去研...

iOS匯入手機通訊錄

abaddressbookref addressbooks nil if uidevice currentdevice systemversion floatvalue 6.0 dispatch semaphore wait sema,dispatch time forever else 獲取通訊錄...

ios手機通訊錄匯入應用

abaddressbookref addressbooks nil if uidevice currentdevice systemversion floatvalue 6.0 dispatch semaphore wait sema,dispatch time forever else 獲取通訊錄...