VCF with Xojo?

I have been asked if I can take an phone list that is in excel and create VCF (Virtual Contact Format) files (?) that can be emailed to everyone on the list so they have all have each other phone numbers automagically on their phones (Android and iPhones)… Too many to hand enter.

Has anybody done something like this? Is is difficult… what would I have to do?

I am aware that VCF exists but I know nothing about it.

Thanks,

  • karen

what you are talking about is VCard format… Super simple to create using Xojo.
years back I did some project, where I did just what you are describing… it actually took data from multiple files and spit out a VCard file that was then loaded into their contacts list.

The Apple Address book can export data in this format, and it should be simple to reverse engineer it, thats what I did. :slight_smile:

no need to reverse …
https://tools.ietf.org/html/rfc6350

I know one of your concerns is usually cost, but I don’t recall if you’re a fan of plugins.
Have you considered how you’re going to read the excel file? If it’s not CSV, you may need an Excel plugin to handle it. I do like Einhugur’s Excel plugins, I just recently used the writer to generate some reports and it was easy and straightforward.

[quote=420241:@Tim Parnell]I know one of your concerns is usually cost, but I don’t recall if you’re a fan of plugins.
Have you considered how you’re going to read the excel file? If it’s not CSV, you may need an Excel plugin to handle it. I do like Einhugur’s Excel plugins, I just recently used the writer to generate some reports and it was easy and straightforward.[/quote]

I have the Einhugur Plugins but for this the simplest thing is just to save the excel file as Tab delimited text… reading that in is trival… I use that approach often.

I have considered using Excel Reader but it just does not seem worth the bother given how easy it is to deal with tab delimited text file for simple lists. (I do use Excel Writer however for other things)

  • karen

[quote=420239:@Dave S]what you are talking about is VCard format… Super simple to create using Xojo.
years back I did some project, where I did just what you are describing… it actually took data from multiple files and spit out a VCard file that was then loaded into their contacts list.
[/quote]

So can you just attach the file to an Email and have the list imported into their contact list on their phone when you email it to them. Do the recipients have to do anything specific when they get the Email?

  • Karen

I believe the have to open their Contacts/Address Book app and Import the file…
They may be able to double click it, you’d have to test that I don’t recall its been quite a while.

The app I wrote took it from an SQLite database and exported it…

Also… you don’t HAVE to include all the fields specified in the Standard… just those that you have

[quote=420241:@Tim Parnell]I know one of your concerns is usually cost, but I don’t recall if you’re a fan of plugins.
Have you considered how you’re going to read the excel file? If it’s not CSV, you may need an Excel plugin to handle it. I do like Einhugur’s Excel plugins, I just recently used the writer to generate some reports and it was easy and straightforward.[/quote]

No need for plugins, just Go to excel (Or any compatible app) and do a Save As CSV took les than a minute.

[quote=420240:@Jean-Yves Pochez]no need to reverse …
https://tools.ietf.org/html/rfc6350[/quote]

For this kind of proyect there is no need to learn the entire format.

Jus grab your phone, go to contacts, select one and edit it with all the fields you need in the vCard. Share the contact as vCard, send it yo your mail. Download it in your computer, open it as a plain text file.

All you need to do is create text files with the same structure.

Here is the code the I used to EXPORT a VCARD… it will not be a plug-n-play for you, but it might give you some ideas. I also have an IMPORT function as well.

CODE IS SUPPLIED AS-IS FOR ILLUSTRATION PURPOSE ONLY

This was written maybe 8-10 years ago?

Public Sub EXPORT_VCARD(record_id As Integer,file_open as boolean=true, file_close as boolean=true,use_list as boolean=false)
  Dim SQL As String
  Dim rs As RecordSet
  Dim x As Integer
  Dim y As Integer
  Dim flag As Boolean
  Dim s As String
  Dim v(6) As String
  
  s=""
  If file_open Then 
    Export_File_Create tbl_CONTACTS,record_id,True
  End If
  //
  SQL="SELECT COUNT(*) AS CNT from '"+tbl_contacts+"' WHERE name is NOT NULL"
  If record_id>0 Then SQL=SQL+" and id="+Str(record_id)
  flag=DB_Select(SQL,rs)
  If flag Then
    x=rs.field("cnt").IntegerValue
  Else
    x=0
  End If
  '
  If x>0 Then
    //
    SQL= _
    "SELECT DISTINCT "+_
    "       name,"+_
    "     company,"+_
    "     address,"+_
    "        city,"+_
    "       state,"+_
    "         zip,"+_
    "       phone,"+_
    "        cell,"+_
    "       email," +_
    "     website,"+_
    "     birthday,"+_
    "  anniversary,"+_
    "       notes" +_
    " FROM '"+tbl_contacts+"' WHERE name IS NOT NULL"
    If record_id>0 Then SQL=SQL+" and id="+Str(record_id)
    SQL=SQL+" ORDER BY name"
    flag=DB_Select(SQL,rs)
    If flag Then
      While Not rs.eof
        xml_write "BEGIN:VCARD"
        xml_write "VERSION:3.0"
        //
        s=String_to_VCard_Name(Trim(rs.field("name").StringValue))
        If s<>"" Then
          xml_write "N:"+s
          s=VCard_Name_to_string(s,False)
          xml_write "FN:"+s
        End If
        '
        s=Trim(rs.Field("company").StringValue)
        If s<>"" Then xml_write "ORG:"+s
        '
        v(0)=""
        v(1)=""
        v(2)=Trim(rs.field("address"))
        v(3)=Trim(rs.field("city"))
        v(4)=Trim(rs.field("state"))
        v(5)=Trim(rs.field("zip"))
        v(6)=""
        xml_write "ADR;type=HOME:"+Join(v,";")
        
        s=Trim(rs.field("phone").StringValue)
        If s<>"" Then xml_write "TEL;TYPE=home:"+s
        '
        s=Trim(rs.field("cell").StringValue)
        If s<>"" Then xml_write "TEL;TYPE=cell:"+s
        '
        s=Trim(rs.field("email").StringValue)
        If s<>"" Then xml_write "EMAIL;type=INTERNET;type=HOME:"+s
        '
        s=Trim(rs.field("website").StringValue)
        If s<>"" Then xml_write "URL:"+s
        //
        s=Trim(rs.field("birthday").StringValue)
        If s<>"" Then
          s=OUTPUT_DATE(s) ' yyyymmdd
          xml_write "BDAY;value=date:"+Left(s,4)+"-"+Mid(s,5,2)+"-"+Right(s,2)
        End If
        //
        s=Trim(rs.field("anniversary").StringValue)
        If s<>"" Then
          s=OUTPUT_DATE(s) ' yyyymmdd
          'xml_write "X-ANNIVERSARY:"+left(s,4)+"-"+mid(s,5,2)+"-"+right(s,2)
          xml_write "item1.X-ABDATE:"+Left(s,4)+"-"+Mid(s,5,2)+"-"+Right(s,2)
          xml_write "item1.X-ABLabel:_$!<Anniversary>!$_"
        End If
        '
        s=Trim(rs.field("notes").StringValue)
        If s<>"" Then
          s=ReplaceAll(s,"<br>","\
")
          s=ReplaceAll(s,"<b>","")
          s=ReplaceAll(s,"<i>","")
          s=ReplaceAll(s,"<u>","")
          s=ReplaceAll(s,"<p>","")
          x=InStr(s,"<#")
          While x>0
            y=InStr(x,s,">")
            s=Left(s,x-1)+Mid(s,y+1)
            x=InStr(s,"<#")
          Wend
          s=Trim(s)
          While Right(s,2)="\
"
            s=Trim(Left(s,Len(s)-2))
          Wend
          s=ReplaceAll(s,",","\\,")
          s=ReplaceAll(s,":","\\:")
          If s<>"" Then xml_write "NOTE:"+s
        End If
        //
        xml_write "END:VCARD"
        rs.MoveNext
      Wend
    End If
    //
  End If
  If file_close Then Export_File_Close True
End Sub



Private Sub XML_Write(s As String)
  Dim i As Integer
  If XML_Indent>0 and XML_Encrypt_Key="" Then
    For i=1 To XML_Indent*3
      XML_OutFile.Write " "
    Next
  End If
  if XML_Encrypt_Key<>"" then s=ENcodebase64(rc4(s,XML_Encrypt_Key),0)
  XML_OutFile.Write s+EOL
End Sub


Private Sub Export_File_Create(tbl_name as string, rec_id as integer, is_vcard as boolean = false)
  Dim s As String
  Dim XML_Serial As String
  Dim r As New random
  XML_Encrypt_Key=""
  If is_vcard Then 
    s=pgm_name+"_contacts.vcf"
  Else
    s=pgm_name+"_export_"+tbl_name
    If rec_id>0 Then s=s+"_R"+Str(rec_id)
    s=s+Ext_Export
    // Ask if user wants export encrypted
    If option_encrypt_exports Then 
      XML_SERIAL=Str(r.inrange(12345678,99999999))
      XML_Encrypt_Key=Get_Password(xml_serial)
    End If
  End If
  XML_OutPath=SpecialFolder.Desktop.child(s)
  If XML_OutPath.exists Then XML_OutPath.delete
  XML_OutFile=TextOutputStream.Create(XML_OutPath)
  XML_indent=0
  If Not is_vcard Then 
    If xml_serial<>"" Then XML_OutFile.Write "SALT:"+encodebase64(rc4(XML_SERIAL,salt))+EOL
    XML_Write XML_Header 
  End If
End Sub

You entirely missed the point of my post in order to try to correct me on something. You didn’t even bother to read the whole post. Please stop acting like this, it’s immature and not appreciated.

Yes, by me, see www.excel2vCard.com . It has been created with Xojo and Christian’s XL-plugin and got good reviews on the App Store (https://itunes.apple.com/us/app/excel2vcard/id994556965?mt=12). It sells very well (at around 10USD for a license, but it is free to try).

vCards are just text files that have a “vcf” extension. Here’s some FileMaker code that I used long ago to export vCards. You just repeat this for each contact that you grab from the Excel file. :slight_smile:

the_vCard = “BEGIN:VCARD¶VERSION:2.1¶” ;
the_vCard = the_vCard & “N:” & the_vname & “¶” ;
the_vCard = the_vCard & “FN:” & the_vfname & “¶” ;
the_vCard = the_vCard & “ORG:” & the_vorg & “;¶” ;
the_vCard = the_vCard & the_Phones ;
the_vCard = the_vCard & the_Email ;
the_vCard = the_vCard & the_Addr ;
the_vCard = the_vCard & If ( IsEmpty ( IsOrganization ) ; “” ; “X-ABShowAs:COMPANY” & “¶” ) ;
the_vCard = the_vCard & If ( Count ( Contacts.ContactsCategories::_ID ) = 0 ; “” ; “CATEGORIES:” & Substitute ( List ( Contacts.ContactsCategories::CategoryName ) ; “¶” ; “,” ) & “¶” ) ;
the_vCard = the_vCard & “NOTE:” & Filter ( Substitute ( TextWhitespaceTrim ( Notes ) ; [ “¶”;"
“] ; [ “,”;”\,"] ; [ “:”;"\:"] ; [ “;”;"\;"] ) ; the_Filter) & “¶” ; ;
the_vCard = the_vCard & “END:VCARD¶¶”

FYI, FileMaker uses & to append strings and ¶ represents a char(13). If you have any questions about any of this just ask…

More about vCards: https://en.wikipedia.org/wiki/VCard

I saw that I’m using a very old vCard version, but I bet it still works fine.

I hope this helps!

Hal’s code uses VCard 2.1, the code example I posted was VCard 3.0 … not real sure what the specific differences are

Thanks all… I have all I need… all I really need for this are the name fields, Organization Email and Cell Phone number so i don’t need most of the fields.

This will be very simple…

Thanks

  • karen