1

我正在编写一个简单的脚本,它使用 Excel 电子表格作为源来生成许多 Vcard(我们的内部公司电话列表)。

我可以成功地查询电子表格,使用 xlrd 模块获取电话号码、电子邮件地址等。我还在脚本中硬编码了一些信息(注释等),以便我可以在输入所有信息之前检查基本功能在电子表格中。除了我无法将传真号码写入 Vcard 之外,所有操作似乎都正常。我正在使用 MS Outlook 在生成 Vcard 后打开它们,因此不确定是否存在问题。当我用文本编辑器打开卡片时,我觉得一切正常。

欢迎大家指教!

谢谢!

from xlrd import open_workbook
import vobject
Address_book_spreadsheet = 'C:\\Address.xls'
Address_book_object = open_workbook(Address_book_spreadsheet, 'rb')
Address_book = Address_book_object.sheet_by_index(1)
Number_of_entries = Address_book.nrows
Pointer =  1


print Address_book_object
print Number_of_entries
print Pointer
print Address_book.cell(Pointer,1)

for row_index in range (Number_of_entries - 1):
    surname = str(Address_book.cell(Pointer,3).value)
    christian_name = str(Address_book.cell(Pointer,0).value)
    email = str(Address_book.cell(Pointer,10).value)
    mobile = str(Address_book.cell(Pointer,7).value)
    business_phone = str(Address_book.cell(Pointer,6).value)

    output_file = "C:\\" + surname + '_' + christian_name + ".vcf"
    fout = open(output_file, 'w')
    j = vobject.vCard()

    o= j.add('fn')
    o.value = christian_name + surname

    o = j.add('n')
    o.value = vobject.vcard.Name( family= surname, given= christian_name )


    o= j.add('email')
    o.type_param = 'INTERNET'
    o.value = email


    o= j.add('tel')
    o.type_param = 'CELL'
    o.value = '66666666666'

    o = j.add('tel')
    o.type_param = 'WORK'
    o.value = '55555555'

    o = j.add('tel')
    o.type_param = 'HOME'
    o.value = '+61 8 0000 4448'

    o = j.add('tel')
    o.type_param = 'FAX'
    o.value = '+61 8 000 4448'

    o=j.add('tel')
    o.type_param = 'RADIO'
    o.value = 'HUD269' 

    o=j.add('org')
    o.value = ["Charlie's Chocolate Factory"]

    o=j.add ('adr')
    o.type_param = 'BUSINESS'
    o.value.street = 'Chocolate Factory Road'
    o.value.region = 'Western Australia'
    o.value.city = 'Perth'
    o.value.country = 'Australia'
    o.value.code = '6000'

    o=j.add('url')
    o.type_param = 'BUSINESS'
    o.value = 'www.charlie_chocolate.net.au'

    o=j.add('note')
    o.value = 'A very very nice person!'


    j.serialize()

    print j

    j.prettyPrint()

    fout.write (j.serialize())
    fout.close()
    Pointer = Pointer + 1 




BEGIN:VCARD

VERSION:3.0

ADR;TYPE=BUSINESS:;;Chocolate Factory Road;Perth;Western Australia;6000;Australia

EMAIL;TYPE=INTERNET:rkent@mother.net.au

FN:RobertKent

N:Kent;Robert;;;

NOTE:A very very nice person!

ORG:Charlie's Chocolate Factory

TEL;TYPE=CELL:66666666666

TEL;TYPE=WORK:55555555

TEL;TYPE=HOME:+61 8 0000 4448

TEL;TYPE=FAX:+61 8 000 4448

TEL;TYPE=RADIO:HUD269

URL;TYPE=BUSINESS:www.charlie_chocolate.net.au

END:VCARD
4

0 回答 0