买了iPhone麻烦也挺多的,通讯录的迁移就是个问题,还好没事闲的去折腾了代码,折腾好了迁移。

一、首先要通过软件,qq通讯录也罢,360助手也罢导出通讯录到Excel

二、Excel导出为vCard通讯录模式

代码如下:

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
Dim objXLApp, objXLWb, objXLWs
Dim cellValue
Dim outFile
Dim row,col
Set objXLApp = CreateObject("Excel.Application")
objXLApp.Visible = True
Set objXLWb = objXLApp.Workbooks.Open("D:\1.xlsx")
'~~> Working with Sheet1
Set objXLWs = objXLWb.Sheets(1)
Set objFSO=CreateObject("Scripting.FileSystemObject")
outFile="D:\connect.txt"
Set objFile = objFSO.CreateTextFile(outFile,True)
With objXLWs
For row =2 To 463
objFile.Write "BEGIN:VCARD" & vbCrLf
objFile.Write "VERSION:3.0" & vbCrLf
objFile.Write "FN;CHARSET=UTF-8:"
cellValue = .Cells(row,5).Value
objFile.Write cellValue & vbCrLf
objFile.Write "N;CHARSET=UTF-8:"
cellValue = .Cells(row,5).Value
objFile.Write cellValue & vbCrLf
objFile.Write "TEL;TYPE=CELL:"
cellValue = .Cells(row,41).Value
objFile.Write cellValue & vbCrLf
objFile.Write "END:VCARD" & vbCrLf
Next
objFile.Close
End With
'~~> Save as Excel File (xls) to retain format
'objXLWb.SaveAs "D:\new.xls", 56
'~~> File Formats
'51 = xlOpenXMLWorkbook (without macro's in 2007-2010, xlsx)
'52 = xlOpenXMLWorkbookMacroEnabled (with or without macro's in 2007-2010, xlsm)
'50 = xlExcel12 (Excel Binary Workbook in 2007-2010 with or without macro's, xlsb)
'56 = xlExcel8 (97-2003 format in Excel 2007-2010, xls)
objXLWb.Close (False)
Set objXLWs = Nothing
Set objXLWb = Nothing
objXLApp.Quit
Set objXLApp = Nothing

解释:

  1. 第10行表示输入文件为D盘的名为1.xlsx的Excel文件。
  2. 第17行表示输出文件在D盘contect.txt
  3. 第20行至第33表示循环打印通讯录vCard的内容,格式采用如下:
1
2
3
4
5
6
BEGIN:VCARD
VERSION:3.0
FN;CHARSET=UTF-8:张老班
N;CHARSET=UTF-8:张老班
TEL;TYPE=CELL:1065750247681958
END:VCARD

三、将vCard文件导入手机,用通讯录打开即可。

备注:从iCloud上导出的vCard

时间是在2015-02-12 13:12

1
2
3
4
5
6
7
8
9
10
11
BEGIN:VCARD
VERSION:3.0
PRODID:-//Apple Inc.//iOS 8.1.2//EN
N:“姓氏”;“名字”;;;
FN:“名字” “姓氏”
ORG:“公司”;
EMAIL;type=INTERNET;type=HOME;type=pref:example@example.con
TEL;type=HOME;type=VOICE;type=pref:0560-3861234
TEL;type=CELL;type=VOICE:152-1234-9876
REV:2015-02-12T13:26:12Z
END:VCARD

分别是姓氏、名字、公司、邮件、家庭电话、手机。