I'm writing a simple script that uses an excel spreadsheet as a source to produce a number of Vcards (our internal company telephone list).
I can successfully interrogate the spreadsheet, using the xlrd module to gain phone numbers, email addresses etc. I've also hard coded some of the information (notes etc) within the script so that I can check the basic function before putting all the information in the spreadsheet. All appear to operate correctly, except I can't write the Fax numbers to the Vcard. I'm using MS Outlook to open the Vcards after they're generated and am therefore unsure if the problem is there. All looks to be OK to me when I open the card with a text editor.
All advise welcome!
Thanks!
Rob
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:[email protected]
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