手機通訊錄導入工具

在寫文章之前我想先說一句,希望尊重別人的勞動成果,轉載或者抄襲後在末尾加上原文的鏈接是對作者的尊重,也是鼓勵作者再接再厲發帖的動力。

 

現在的手機五花八門,手機系統也多種多樣,聯繫人的導入導出成了問題。爲了自己,也爲了身邊的朋友,花了2天時間用VB做了一個小工具,大致原理如下:

不管什麼系統安卓,windows,塞班,還是國產(愛瘋由於沒那個資金投入沒做測試)都是支持國際通用的vcf格式,所以只需要將你的聯繫人做成這種格式就可以在很多手機上通用,VCF本身支持很多參數,以下是一個標準的VCF文件內容

  1. BEGIN:VCARD  
  2. VERSION:3.0  
  3. N:Lastname;Firstname;;;  
  4. FN:Fullname  
  5. NICKNAME:Alias  
  6. TEL;CELL;VOICE:PrimaryCell  
  7. TEL;CELL;VOICE:SecondaryCell  
  8. TEL;WORK;VOICE:WorkNum1  
  9. TEL;WORK;VOICE:WorkNum2  
  10. TEL;HOME;VOICE:HomeNum1  
  11. TEL;HOME;VOICE:HomeNum2  
  12. TEL;HOME;VOICE:RadioNum  
  13. TEL;WORK;FAX:WorkFax  
  14. TEL;HOME;FAX:HomeFax  
  15. TEL;TYPE=ISDN:ISDNNum  
  16. EMAIL;PREF;INTERNET:Email1  
  17. EMAIL;INTERNET:Email2  
  18. EMAIL;INTERNET:Email3  
  19. URL:Website  
  20. ORG:Organization  
  21. TITLE:Grade  
  22. BDAY:Birthday  
  23. ADR;TYPE=WORK;CHARSET=UTF-8:WorkStreet3;WorkStreet2;WorkStreet1;WorkCity;WorkProvince;WorkPostalcode;WorkState  
  24. ADR;TYPE=HOME;CHARSET=UTF-8:HomeStreet3;HomeStreet2;HomeStreet1;HomeCity;HomeProvince;HomePostalcode;HomeState  
  25. END:VCARD 

 

語法很簡單,根據英文簡寫就能猜到是什麼東東。

只需要在上面的內容中輸入自己聯繫人信息就可以了,但是一個個輸入工作量太大也不太現實,所以就想到了做一個小腳本從Excel表格中一個個去“拿”數據,並且自動做成一個個vCards文件將這些文件拷貝到手機卡就可以導入了,非安卓手機必須一個個導入,安卓可以支持合併的聯繫人文件導入(批量導入),並且安卓系統支持VCF LABEL字段,所以整個程序設計起來就分爲了安卓與非安卓兩個方案。

實現過程:

1.數據源:就一個Excel表格,第一次可能需要自己花些時間將自己的聯繫人輸入到程序指定的Excel中。

2.VCF模板

通過複製VCF標準模板,程序將讀取到得數據替換模板的內容,最終保存爲VCF聯繫人。

3.讀取Excel數據並製成VCF的腳本

  1. Const ForReading=1 
  2. Const ForWriting=2 
  3. Const ForAppending=8 
  4. Const OverwriteExisting = True 
  5. Const DeleteReadOnly = True 
  6.  
  7. Varsystem = UCase(InputBox("請選擇你的手機系統."  & VbCrLf & "1.Android."  & VbCrLf & "2.Other."))  
  8.  
  9. If Varsystem = "" then  
  10. wscript.quit  
  11. End If  
  12.  
  13. If Not IsNumeric(Varsystem) then  
  14. wscript.echo "你的輸入有誤"  
  15. wscript.quit  
  16. End If  
  17.  
  18. If Varsystem >=3 then  
  19. wscript.echo "請輸入數字1-2"  
  20. wscript.quit  
  21. End If  
  22.  
  23.     Select Case Varsystem  
  24.     Case 1  
  25.         strStatus = "Android" 
  26.     Case 2  
  27.         strStatus = "Other" 
  28.     End Select  
  29.  
  30. 'Define VcfFolder Path  
  31. StrVcfFolder = "vCards" 
  32. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  33. If not objFSO.FolderExists(StrVcfFolder) Then  
  34.     Set objFolder = objFSO.CreateFolder(StrVcfFolder)  
  35. End If  
  36.  
  37. 'Define data and path  
  38. Set objShell = CreateObject("Wscript.Shell")  
  39. strCurPath = objShell.CurrentDirectory  
  40. strDataPath = strCurPath & "\Data"  
  41. strxlsfile = strDataPath & "\Contact.xls"  
  42. strTempPath = strCurPath & "\templet"  
  43. strTempfile = strTempPath & "\" & strStatus & ".vcf"  
  44. stroldvcfs = strCurPath & "\vCards\*.*"  
  45.  
  46. 'Delete old vcf files  
  47. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  48. objFSO.DeleteFile(stroldvcfs), DeleteReadOnly  
  49.  
  50. 'locate source data file  
  51. Set objExcel = CreateObject("Excel.Application")  
  52. Set objWorkbook = objExcel.Workbooks.Open(strxlsfile)  
  53. Set objWorksheet = objWorkbook.Worksheets(1)  
  54.  
  55. Dim i, count  
  56. i = 3 
  57. count = 0 
  58.  
  59. Do Until objExcel.Cells(i, 1).Value = "" 
  60. strFullname = objExcel.Cells(i, 1).Value  
  61. strLastname = objExcel.Cells(i, 2).Value  
  62. strFirstname = objExcel.Cells(i, 3).Value  
  63. strAlias = objExcel.Cells(i, 4).Value  
  64. strPrimaryCell = objExcel.Cells(i, 5).Value  
  65. strSecondaryCell = objExcel.Cells(i, 6).Value  
  66. strWorkNum1 = objExcel.Cells(i, 7).Value  
  67. strWorkNum2 = objExcel.Cells(i, 8).Value  
  68. strWorkFax = objExcel.Cells(i, 9).Value  
  69. strHomeNum1 = objExcel.Cells(i, 10).Value  
  70. strHomeNum2 = objExcel.Cells(i, 11).Value  
  71. strHomeFax = objExcel.Cells(i, 12).Value  
  72. strRadioNum = objExcel.Cells(i, 13).Value  
  73. strISDNNum = objExcel.Cells(i, 14).Value  
  74. strEmail1 = objExcel.Cells(i, 15).Value  
  75. strEmail2 = objExcel.Cells(i, 16).Value  
  76. strEmail3 = objExcel.Cells(i, 17).Value  
  77. strWebsite = objExcel.Cells(i, 18).Value  
  78. strOrganization = objExcel.Cells(i, 19).Value  
  79. strGrade = objExcel.Cells(i, 20).Value  
  80. strQQnum = objExcel.Cells(i, 21).Value  
  81. strMSNum = objExcel.Cells(i, 22).Value  
  82. strGoogletalk = objExcel.Cells(i, 23).Value  
  83. strBirthday = objExcel.Cells(i, 24).Value  
  84. strWorkStreet3 = objExcel.Cells(i, 25).Value  
  85. strWorkStreet2 = objExcel.Cells(i, 26).Value  
  86. strWorkStreet1 = objExcel.Cells(i, 27).Value  
  87. strWorkCity = objExcel.Cells(i, 28).Value  
  88. strWorkProvince = objExcel.Cells(i, 29).Value  
  89. strWorkPostalcode = objExcel.Cells(i, 30).Value  
  90. strWorkState = objExcel.Cells(i, 31).Value  
  91. strHomeStreet3 = objExcel.Cells(i, 32).Value  
  92. strHomeStreet2 = objExcel.Cells(i, 33).Value  
  93. strHomeStreet1 = objExcel.Cells(i, 34).Value  
  94. strHomeCity = objExcel.Cells(i, 35).Value  
  95. strHomeProvince = objExcel.Cells(i, 36).Value  
  96. strHomePostalcode = objExcel.Cells(i, 37).Value  
  97. strHomeState = objExcel.Cells(i, 38).Value  
  98.  
  99. 'copy from templet.vcf  
  100. strFilename = objExcel.Cells(i, 1).Value & ".vcf"  
  101. strDstPathfile = strCurPath & "\" & StrVcfFolder & "\" & strFilename  
  102. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  103. objFSO.CopyFile strTempfile, strDstPathfile, OverwriteExisting  
  104.  
  105. '=========================================================1  
  106. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  107. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  108. strText = objFile.ReadAll  
  109. objFile.Close  
  110. strNewText = Replace(strText, "Fullname", strFullname)  
  111. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  112. objFile.WriteLine strNewText  
  113. objFile.Close  
  114.  
  115. '=========================================================2  
  116. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  117. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  118. strText = objFile.ReadAll  
  119. objFile.Close  
  120. strNewText = Replace(strText, "Lastname", strLastname)  
  121. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  122. objFile.WriteLine strNewText  
  123. objFile.Close  
  124.  
  125. '=========================================================3  
  126. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  127. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  128. strText = objFile.ReadAll  
  129. objFile.Close  
  130. strNewText = Replace(strText, "Firstname", strFirstname)  
  131. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  132. objFile.WriteLine strNewText  
  133. objFile.Close  
  134.  
  135. '=========================================================4  
  136. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  137. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  138. strText = objFile.ReadAll  
  139. objFile.Close  
  140. strNewText = Replace(strText, "Alias", strAlias)  
  141. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  142. objFile.WriteLine strNewText  
  143. objFile.Close  
  144.  
  145. '=========================================================5  
  146. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  147. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  148. strText = objFile.ReadAll  
  149. objFile.Close  
  150. strNewText = Replace(strText, "PrimaryCell", strPrimaryCell)  
  151. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  152. objFile.WriteLine strNewText  
  153. objFile.Close  
  154.  
  155. '=========================================================6  
  156. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  157. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  158. strText = objFile.ReadAll  
  159. objFile.Close  
  160. strNewText = Replace(strText, "SecondaryCell", strSecondaryCell)  
  161. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  162. objFile.WriteLine strNewText  
  163. objFile.Close  
  164.  
  165. '=========================================================7  
  166. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  167. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  168. strText = objFile.ReadAll  
  169. objFile.Close  
  170. strNewText = Replace(strText, "WorkNum1", strWorkNum1)  
  171. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  172. objFile.WriteLine strNewText  
  173. objFile.Close  
  174.  
  175. '=========================================================8  
  176. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  177. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  178. strText = objFile.ReadAll  
  179. objFile.Close  
  180. strNewText = Replace(strText, "WorkNum2", strWorkNum2)  
  181. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  182. objFile.WriteLine strNewText  
  183. objFile.Close  
  184.  
  185. '=========================================================9  
  186. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  187. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  188. strText = objFile.ReadAll  
  189. objFile.Close  
  190. strNewText = Replace(strText, "WorkFax", strWorkFax)  
  191. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  192. objFile.WriteLine strNewText  
  193. objFile.Close  
  194.  
  195. '========================================================10  
  196. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  197. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  198. strText = objFile.ReadAll  
  199. objFile.Close  
  200. strNewText = Replace(strText, "HomeNum1", strHomeNum1)  
  201. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  202. objFile.WriteLine strNewText  
  203. objFile.Close  
  204.  
  205. '========================================================11  
  206. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  207. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  208. strText = objFile.ReadAll  
  209. objFile.Close  
  210. strNewText = Replace(strText, "HomeNum2", strHomeNum2)  
  211. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  212. objFile.WriteLine strNewText  
  213. objFile.Close  
  214.  
  215. '========================================================12  
  216. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  217. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  218. strText = objFile.ReadAll  
  219. objFile.Close  
  220. strNewText = Replace(strText, "HomeFax", strHomeFax)  
  221. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  222. objFile.WriteLine strNewText  
  223. objFile.Close  
  224.  
  225. '========================================================13  
  226. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  227. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  228. strText = objFile.ReadAll  
  229. objFile.Close  
  230. strNewText = Replace(strText, "RadioNum", strRadioNum)  
  231. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  232. objFile.WriteLine strNewText  
  233. objFile.Close  
  234.  
  235. '========================================================14  
  236. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  237. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  238. strText = objFile.ReadAll  
  239. objFile.Close  
  240. strNewText = Replace(strText, "ISDNNum", strISDNNum)  
  241. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  242. objFile.WriteLine strNewText  
  243. objFile.Close  
  244.  
  245. '========================================================15  
  246. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  247. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  248. strText = objFile.ReadAll  
  249. objFile.Close  
  250. strNewText = Replace(strText, "Email1", strEmail1)  
  251. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  252. objFile.WriteLine strNewText  
  253. objFile.Close  
  254.  
  255. '========================================================16  
  256. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  257. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  258. strText = objFile.ReadAll  
  259. objFile.Close  
  260. strNewText = Replace(strText, "Email2", strEmail2)  
  261. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  262. objFile.WriteLine strNewText  
  263. objFile.Close  
  264.  
  265. '========================================================17  
  266. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  267. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  268. strText = objFile.ReadAll  
  269. objFile.Close  
  270. strNewText = Replace(strText, "Email3", strEmail3)  
  271. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  272. objFile.WriteLine strNewText  
  273. objFile.Close  
  274.  
  275. '========================================================18  
  276. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  277. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  278. strText = objFile.ReadAll  
  279. objFile.Close  
  280. strNewText = Replace(strText, "Website", strWebsite)  
  281. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  282. objFile.WriteLine strNewText  
  283. objFile.Close  
  284.  
  285. '========================================================19  
  286. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  287. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  288. strText = objFile.ReadAll  
  289. objFile.Close  
  290. strNewText = Replace(strText, "Organization", strOrganization)  
  291. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  292. objFile.WriteLine strNewText  
  293. objFile.Close  
  294.  
  295. '========================================================20  
  296. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  297. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  298. strText = objFile.ReadAll  
  299. objFile.Close  
  300. strNewText = Replace(strText, "Grade", strGrade)  
  301. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  302. objFile.WriteLine strNewText  
  303. objFile.Close  
  304.  
  305. '========================================================21  
  306. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  307. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  308. strText = objFile.ReadAll  
  309. objFile.Close  
  310. strNewText = Replace(strText, "QQnum", strQQnum)  
  311. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  312. objFile.WriteLine strNewText  
  313. objFile.Close  
  314.  
  315. '========================================================22  
  316. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  317. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  318. strText = objFile.ReadAll  
  319. objFile.Close  
  320. strNewText = Replace(strText, "MSNum", strMSNum)  
  321. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  322. objFile.WriteLine strNewText  
  323. objFile.Close  
  324.  
  325. '========================================================23  
  326. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  327. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  328. strText = objFile.ReadAll  
  329. objFile.Close  
  330. strNewText = Replace(strText, "Googletalk", strGoogletalk)  
  331. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  332. objFile.WriteLine strNewText  
  333. objFile.Close  
  334.  
  335. '========================================================24  
  336. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  337. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  338. strText = objFile.ReadAll  
  339. objFile.Close  
  340. strNewText = Replace(strText, "Birthday", strBirthday)  
  341. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  342. objFile.WriteLine strNewText  
  343. objFile.Close  
  344.  
  345. '========================================================25  
  346. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  347. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  348. strText = objFile.ReadAll  
  349. objFile.Close  
  350. strNewText = Replace(strText, "WorkStreet3", strWorkStreet3)  
  351. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  352. objFile.WriteLine strNewText  
  353. objFile.Close  
  354.  
  355. '========================================================26  
  356. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  357. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  358. strText = objFile.ReadAll  
  359. objFile.Close  
  360. strNewText = Replace(strText, "WorkStreet2", strWorkStreet2)  
  361. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  362. objFile.WriteLine strNewText  
  363. objFile.Close  
  364.  
  365. '========================================================27  
  366. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  367. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  368. strText = objFile.ReadAll  
  369. objFile.Close  
  370. strNewText = Replace(strText, "WorkStreet1", strWorkStreet1)  
  371. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  372. objFile.WriteLine strNewText  
  373. objFile.Close  
  374.  
  375. '========================================================28  
  376. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  377. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  378. strText = objFile.ReadAll  
  379. objFile.Close  
  380. strNewText = Replace(strText, "WorkCity", strWorkCity)  
  381. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  382. objFile.WriteLine strNewText  
  383. objFile.Close  
  384.  
  385. '========================================================29  
  386. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  387. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  388. strText = objFile.ReadAll  
  389. objFile.Close  
  390. strNewText = Replace(strText, "WorkProvince", strWorkProvince)  
  391. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  392. objFile.WriteLine strNewText  
  393. objFile.Close  
  394.  
  395. '========================================================30  
  396. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  397. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  398. strText = objFile.ReadAll  
  399. objFile.Close  
  400. strNewText = Replace(strText, "WorkPostalcode", strWorkPostalcode)  
  401. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  402. objFile.WriteLine strNewText  
  403. objFile.Close  
  404.  
  405. '========================================================31  
  406. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  407. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  408. strText = objFile.ReadAll  
  409. objFile.Close  
  410. strNewText = Replace(strText, "WorkState", strWorkState)  
  411. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  412. objFile.WriteLine strNewText  
  413. objFile.Close  
  414.  
  415. '========================================================32  
  416. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  417. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  418. strText = objFile.ReadAll  
  419. objFile.Close  
  420. strNewText = Replace(strText, "HomeStreet3", strHomeStreet3)  
  421. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  422. objFile.WriteLine strNewText  
  423. objFile.Close  
  424.  
  425. '========================================================33  
  426. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  427. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  428. strText = objFile.ReadAll  
  429. objFile.Close  
  430. strNewText = Replace(strText, "HomeStreet2", strHomeStreet2)  
  431. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  432. objFile.WriteLine strNewText  
  433. objFile.Close  
  434.  
  435. '========================================================34  
  436. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  437. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  438. strText = objFile.ReadAll  
  439. objFile.Close  
  440. strNewText = Replace(strText, "HomeStreet1", strHomeStreet1)  
  441. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  442. objFile.WriteLine strNewText  
  443. objFile.Close  
  444.  
  445. '========================================================35  
  446. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  447. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  448. strText = objFile.ReadAll  
  449. objFile.Close  
  450. strNewText = Replace(strText, "HomeCity", strHomeCity)  
  451. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  452. objFile.WriteLine strNewText  
  453. objFile.Close  
  454.  
  455. '========================================================36  
  456. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  457. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  458. strText = objFile.ReadAll  
  459. objFile.Close  
  460. strNewText = Replace(strText, "HomeProvince", strHomeProvince)  
  461. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  462. objFile.WriteLine strNewText  
  463. objFile.Close  
  464.  
  465. '========================================================37  
  466. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  467. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  468. strText = objFile.ReadAll  
  469. objFile.Close  
  470. strNewText = Replace(strText, "HomePostalcode", strHomePostalcode)  
  471. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  472. objFile.WriteLine strNewText  
  473. objFile.Close  
  474.  
  475. '========================================================38  
  476. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  477. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForReading)  
  478. strText = objFile.ReadAll  
  479. objFile.Close  
  480. strNewText = Replace(strText, "HomeState", strHomeState)  
  481. Set objFile = objFSO.OpenTextFile(strDstPathfile, ForWriting)  
  482. objFile.WriteLine strNewText  
  483. objFile.Close  
  484.  
  485. ii = i + 1  
  486. countcount = count + 1  
  487. Loop  
  488.  
  489. objExcel.Quit  
  490. Wscript.echo "共導入" & count & "個聯繫人" 

到此,單個VCF聯繫人就製作完畢了,拷貝到手機就可以導入了。

4.合併單個聯繫人爲一個

因爲安卓系統支持合併的多聯繫人VCF文件,所以另寫了一個腳本合併所有的聯繫人。

  1. Set objShell = CreateObject("Wscript.Shell")  
  2. strCurPath = objShell.CurrentDirectory  
  3. strVfolder = strCurPath & "\vCards"  
  4. stroutfile = strCurPath & "\contacts.vcf"  
  5. strcmd = "copy /B " & strVfolder & "\*.vcf " & stroutfile  
  6. objShell.Run("%comspec% /c" & strcmd)  
  7. wscript.sleep 2000  
  8. wscript.echo "聯繫人合成完畢!" 

5.合併後發現內容中有很多空行和沒有實際數值的行,寫了個優化腳本,刪除多餘的空白行和沒有值的行。

思路:先將無值行替換成空行再移除空行比較簡單。

  1. On Error Resume Next  
  2.  
  3. Const ForReading=1 
  4. Const ForWriting=2 
  5.  
  6. 'Replace all useless line to blank.  
  7. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  8. Set objFile = objFSO.OpenTextFile("contacts.vcf", ForReading)  
  9.  
  10. Do Until objFile.AtEndOfStream  
  11.     strLine = objFile.Readline  
  12.     strLine = Trim(strLine)  
  13.     strRline = Right(strLine, 1)  
  14.     If strRline = ":" Then  
  15.     strnewline = " " 
  16.     Else  
  17.     strnewline = strLine 
  18.     End if  
  19.     strNewTextstrNewText = strNewText & strnewline & vbCrLf  
  20. Loop  
  21.  
  22. objFile.Close  
  23.  
  24. Set objFile = objFSO.OpenTextFile("contacts.vcf", ForWriting)  
  25. objFile.Write strNewText  
  26. objFile.Close  
  27.  
  28. 'Delete all blank line  
  29. Set objFSO = CreateObject("Scripting.FileSystemObject")  
  30. Set objFile = objFSO.OpenTextFile("contacts.vcf", ForReading)  
  31.  
  32. Do Until objFile.AtEndOfStream  
  33.     strLine = objFile.Readline  
  34.     strLine = Trim(strLine)  
  35.     If Len(strLine) > 0 Then  
  36.         strNewContentsstrNewContents = strNewContents & strLine & vbCrLf  
  37.     End If  
  38. Loop  
  39.  
  40. objFile.Close  
  41.  
  42. Set objFile = objFSO.OpenTextFile("contacts.vcf", ForWriting)  
  43. objFile.Write strNewContents  
  44. objFile.Close  
  45.  
  46. wscript.echo "優化完畢!" 

優化後的vcf就可以導入安卓系統或者上傳到google通訊錄了。

 

PS:附件爲整個程序文件(含使用說明和另兩個驚喜程序^_^)

做的不好別拍磚,支持的留個腳印。

你的支持是我最大的動力。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章