诸如豌豆荚等PC端的手机管理程序,可以导入Outlook导出的csv联系人列表。其他的诸如Skype导出的vcf格式则不能够使用,解决方案就是创建和Outlook导出格式一模一样的csv文件,具体的示例代码如下:
def buildCSVContacts(): ''' 本函数的目的是用来创建和Outlook格式相同的csv文件,方便豌豆荚等软件的导入 ''' import csv #读取从实验室之家导出的数据 rows = [] # 共有三项:姓名,邮箱,电话号码 spamReader = csv.reader(open('I:\\Jiang\\11.csv', 'rb'), delimiter=';', quotechar='"') for row in spamReader: print ', '.join(row) if(len(row[0])): rows.append(row) ## 从Outlook导出的csv格式中获取Title spamReader = csv.reader(open('I:\\Jiang\\bak\\120821.CSV', 'rb'), delimiter=',', quotechar='"') titles = spamReader.next() ## 输出结果 spamWriter = csv.writer(open('I:\\Jiang\\120821.CSV', 'wb'), delimiter=',', quotechar='"') spamWriter.writerow(titles) CODE = 'gbk' for name, email, phone in rows: #print name,email,phone new_row = [] for t in titles: #print "|",t,"|" if (t == u"姓".encode(CODE)): new_row.append(name) elif (t == u"移动电话".encode(CODE)): new_row.append(phone) elif (t == u"电子邮件地址".encode(CODE)): new_row.append(email) else: new_row.append(None) #print new_row spamWriter.writerow(new_row)