vcf2csv and csv2vcf: Converting Android Address Book to and from a Spreadsheet File
(中文版)
I am glad that my wife bought an HTC Aria (running Android) and not an iPhone. So I decided it's worth my time to help her importing her addressbook from a spreadsheet file into her new smart phone. I am sharing three small scripts here so that it's easier for people to convert back and forth between the Android address book file format .vcf and the simple format .csv, which can be more easily edited using a spread sheet program on a computer. For the impatient: uncompress the snapshot and on a linux computer you can:
- generate an editable file:
./qp28bit < contacts.vcf | ./vcf2csv > editable.csv
- edit editable.csv using oocalc or gnumeric
- convert it back for Android to import:
./csv2vcf < editable.csv > new-contacts.vcf
Here are the details:
- qp28bit replaces each quoted-printable
encoded string (which may span multiple lines) in a .vcf file
with 8-bit characters that fits into one line. For example,
./qp28bit contacts.vcf > contacts-8bit.vcf
decodes the quoted-printable strings into a new contact file contacts-8bit.vcf so that the utf-8 encoded Chinese characters are readable and editable using any plain text editor. Sometimes I have to apply this more than once to a vcf file exported by Android. - vcf2csv converts a .vcf file
containing no multiple-line fields into a spread sheet
file. More precisely, (1) it is supposed to process a .vcf file
generated by qp28bit, and (2) the PHOTO field is silently
dropped! For example,
./vcf2csv contacts-8bit.vcf > editable.csv
converts contacts-8bit.vcf into editable.csv, which can be imported into calc (spreadsheet program of OO.o). It accepts the -d option to specify a delimiter other than "," the default delimiter. For example:./csv2vcf -d '#' contacts.vcf > editable.csv
creates a csv file delimited by hash marks instead of commas. - csv2vcf converts a spread sheet file
into an Android address book. For example,
./csv2vcf editable.csv > new-contacts.vcf
converts editable.csv into new-contacts.vcf . It also accepts the -d option to specify a delimiter other than ",".
These scripts are short and crude, meaning that many assumptions are made about the files, and that there is hardly any error checking. Specifically:
- Quotes are not processed. This implies that you cannot have commas in your data, or if you do, you will have to use a delimiter other than comma.
- Contents in an input file (to any of the 3 scripts) are assumed to use the utf8 charset. You can see this assumption explicitly in the code of qp28bit. You may have to pre-process the csv file using iconv if your spread sheet program exports csv files in other encodings (big5, gb2312, ... for example).
- csv2vcs uses 8-bit encoding instead of the original and more elaborate quoted-printable encoding. Anyway it seems acceptable to Android.
- For all scripts, the ouput files uses Linux style newlines -- a newline is one bye (LF) instead of two bytes (CR, LF).
Well, excel can also read/write csv files. But please give OO.o a try next time, ok?
Notes for other Smart Phones and Applications
Different contact managers/address book programs may use slightly different names for the same field. Here is a list of string substitutions to make for smart phones/applications that I happen to have played with.
- For gmail to import the vcf file, you have to change all "EMAIL;INTERNET" to "EMAIL;HOME", like this.
- For zimbra to import the csv file, you need to use following field names: "firstName", "lastName", "fullName", "homePhone", "mobilePhone", "workPhone", "email", "email2",... like this.
Comments?
I have no energy to maintain a full-blown software package and its corresponding maintainence system. However, your comments are most welcome. Please use this blog entry to leave your comments.
History
- 2011/02/07: Complete re-write as 3 modular commands to replace the original 2 messy and buggy commands.
- 2010/08/18: First release
- Most updated version of this page: http://frdm.cyut.edu.tw/~ckhung/p/vcf2csv/; the version you're reading: February 07 2011 11:26:49.
- Author: Chao-Kuei Hung at Chaoyang University Information Management Department
- Save our Earth; please reduce printing, make use of the unprinted side, and recycle.
- You are welcome to distribute this document in accordance with the Creative Commons Attribution-ShareAlike License or the Free Document License.