Tuesday, April 18, 2017

CSV to vcf/vcard converter (advanced edit android contact).

Spreadsheets are great! But only if you could use them to manage contacts, specially in your Android phone (or any standard compliant phone which can export to vcard).

So we got vcf2csv to do the conversion. This program will blindly convert all fields in the vcard (including the standard fields like version) to columns in the generated tab separated CSV. And that's just we want.

Now you got to convert it back to VCF so you can import it to your (standard compliant) phone. To do so, convert using the script (Released under Apache license :p) --


#!/usr/bin/ruby
require 'csv.rb'
header = nil
counter = 0
CSV.foreach(ARGV[0], { :col_sep ="\t", :quote_char ='!' }) {
 |row|
 if counter == 0
  header = row.dup
 else
  puts "BEGIN:VCARD"
  row.each_with_index {
   |data, index|
   if data != nil
    puts "#{header[index]}:#{data}"
   end
  }
  puts "END:VCARD"
 end
 counter += 1
}

First argument is the path of the tab separated CSV to convert. The output of the program is the converted VCARD. It simply converts the columns to vcard fields

4 comments:

  1. If you previously saved your contacts in CSV format and now want to transfer contacts from CSV to vCard, you can download the CSV to VCF Converter tool, which is ideal for exporting CSV to VCF in a few simple steps. In addition, the application contains many useful features that facilitate a conversion.

    More info:- CSV to VCF Converter Software

    ReplyDelete
  2. Very useful! Thanks!

    There are some changes for line 5 (with ruby 2.7). In my case (with changes for my csv file format and adding transcoding from Greek ISO to UTF-8), line 5 became:

    CSV.foreach(ARGV[0], **{ encoding: "ISO-8859-7:UTF-8", col_sep: ";", quote_char: '"' }) {

    Thank you anyway, since it is becoming unnecessarily complex to make this conversion (csv-to-vcf), according to the suggestions you get on the internet! Numerous solutions that cannot be tailored to specific contexts, require tones of software installed and still don't work in the end!

    In my case, ruby was installed (along with something else I installed the other day) and my familiarity with python helped with the warning that Ruby 2.7 gives for the Hash Argument in curly brackets.

    [ I found more on the options acceptable in line 5 from here: https://ruby-doc.org/stdlib-2.6.1/libdoc/csv/rdoc/CSV.html#method-c-new ]

    ReplyDelete
  3. Excel to vCard Converter for the instant conversion of the bulk Excel data files to CSV format in just a couple of moments that too without any data alteration. It enables users to preview the Excel files well before the final conversion of the data to CSV format. Users can convert the files from any android devices such as SamSung, Motorola, OnePlus, etc. It is a 100% safe solution to convert the files format without any technical assistance.

    Read more details:- Excel to vCard Converter

    ReplyDelete
  4. You've really made my day today with this post.
    naprawa dysków

    ReplyDelete