将本地 Outlook 联系人导出到 vcard

发布于 2024-07-30 10:58:07 字数 194 浏览 3 评论 0原文

所有,

我正在尝试编写一个程序,将存储在 Outlook 本地 pst 文件中的所有联系人导出到 vcard

我已经看到了几个共享软件程序可以做到这一点,但它们似乎相当昂贵(50 美元+)

我看到了一个例子在这里,但它似乎更适合交换服务器,而不是 Outlook 的本地安装,

我有什么想法可以解决这个问题吗?

All,

I'm trying to write a program that will export all the contacts stored in the local pst file of outlook to vcards

I have seen several shareware programs that will do it but they seem pretty expensive (50 bucks+)

I have seen an example here but it seems more geared to an exchange server rather than to the local install of outlook

any ideas on how i would go about this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嘿嘿嘿 2024-08-06 10:58:07

这可能适合。

Sub VCardOut()
Dim oFolder As Object
Dim oContact As ContactItem
Dim sPath As String
Dim sName As String
Dim sVCard As String
Dim f As Object
Dim fs As Object
Dim i As Integer


    Set fs = CreateObject("Scripting.FileSystemObject")
    Set oFolder = GetNamespace("MAPI").GetDefaultFolder(olFolderContacts)

    sPath = "C:\Docs\"

'格式和反斜杠问题

    '' Loop through all of the items in the folder.
    For i = 1 To oFolder.Items.Count
        Set oContact = oFolder.Items(i)

        sName = oContact.FullNameAndCompany & ".vcf"

        If Trim(sName) = ".vcf" Then sName = oContact.EntryID & ".vcf"

        Set f = fs.CreateTextFile(sPath & sName)

        sVCard = "BEGIN:VCARD" & vbCrLf
        sVCard = sVCard & "VERSION:2.1" & vbCrLf

        sVCard = sVCard & "FN:" & oContact.FullName & vbCrLf

        sVCard = sVCard & "N:" & oContact.LastName & ";" & oContact.FirstName & ";" _
            & oContact.MiddleName & ";" & oContact.Title & ";" & vbCrLf

        sVCard = sVCard & "NICKNAME:" & oContact.NickName & vbCrLf

        sVCard = sVCard & "ADR;HOME;ENCODING=QUOTED-PRINTABLE:;;" _
            & Replace(oContact.HomeAddress & "", vbCrLf, "=0D=0A") & ";" _
            & Replace(oContact.HomeAddressCity & "", vbCrLf, "=0D=0A") & ";" _
            & Replace(oContact.HomeAddressCountry & "", vbCrLf, "=0D=0A") & vbCrLf

        sVCard = sVCard & "ADR;WORK;ENCODING=QUOTED-PRINTABLE:;;" _
            & Replace(oContact.BusinessAddress & "", vbCrLf, "=0D=0A") & ";" _
            & Replace(oContact.BusinessAddressCity & "", vbCrLf, "=0D=0A") & ";" _
            & Replace(oContact.BusinessAddressCountry & "", vbCrLf, "=0D=0A") & vbCrLf

        sVCard = sVCard & "BDAY:" & Format(oContact.Birthday, "yyyymmdd") & vbCrLf

        sVCard = sVCard & "EMAIL;PREF;INTERNET:" & oContact.Email1Address & vbCrLf

        '' Repeat as necessary for each email address
        sVCard = sVCard & "EMAIL;INTERNET:" & oContact.Email2Address & vbCrLf

        sVCard = sVCard & "ORG:" & oContact.CompanyName & ";" & oContact.Department & vbCrLf

        sVCard = sVCard & "TEL;CELL;VOICE:" & oContact.MobileTelephoneNumber & vbCrLf

        sVCard = sVCard & "TEL;HOME;FAX:" & oContact.HomeFaxNumber & vbCrLf

        sVCard = sVCard & "TEL;HOME;VOICE:" & oContact.HomeTelephoneNumber & vbCrLf

        sVCard = sVCard & "TEL;WORK;FAX:" & oContact.BusinessFaxNumber & vbCrLf

        sVCard = sVCard & "TEL;WORK;VOICE:" & oContact.BusinessTelephoneNumber & vbCrLf

        sVCard = sVCard & "TITLE:" & oContact.JobTitle & vbCrLf

        sVCard = sVCard & "URL;HOME:" & oContact.PersonalHomePage & vbCrLf

        sVCard = sVCard & "URL;WORK:" & oContact.BusinessHomePage & vbCrLf

        sVCard = sVCard & "REV:20090225T232716Z" & vbCrLf
        sVCard = sVCard & "End: VCARD"

        f.WriteLine sVCard
        f.Close
    Next

End Sub

This may suit.

Sub VCardOut()
Dim oFolder As Object
Dim oContact As ContactItem
Dim sPath As String
Dim sName As String
Dim sVCard As String
Dim f As Object
Dim fs As Object
Dim i As Integer


    Set fs = CreateObject("Scripting.FileSystemObject")
    Set oFolder = GetNamespace("MAPI").GetDefaultFolder(olFolderContacts)

    sPath = "C:\Docs\"

'Problem with formatting and backslash

    '' Loop through all of the items in the folder.
    For i = 1 To oFolder.Items.Count
        Set oContact = oFolder.Items(i)

        sName = oContact.FullNameAndCompany & ".vcf"

        If Trim(sName) = ".vcf" Then sName = oContact.EntryID & ".vcf"

        Set f = fs.CreateTextFile(sPath & sName)

        sVCard = "BEGIN:VCARD" & vbCrLf
        sVCard = sVCard & "VERSION:2.1" & vbCrLf

        sVCard = sVCard & "FN:" & oContact.FullName & vbCrLf

        sVCard = sVCard & "N:" & oContact.LastName & ";" & oContact.FirstName & ";" _
            & oContact.MiddleName & ";" & oContact.Title & ";" & vbCrLf

        sVCard = sVCard & "NICKNAME:" & oContact.NickName & vbCrLf

        sVCard = sVCard & "ADR;HOME;ENCODING=QUOTED-PRINTABLE:;;" _
            & Replace(oContact.HomeAddress & "", vbCrLf, "=0D=0A") & ";" _
            & Replace(oContact.HomeAddressCity & "", vbCrLf, "=0D=0A") & ";" _
            & Replace(oContact.HomeAddressCountry & "", vbCrLf, "=0D=0A") & vbCrLf

        sVCard = sVCard & "ADR;WORK;ENCODING=QUOTED-PRINTABLE:;;" _
            & Replace(oContact.BusinessAddress & "", vbCrLf, "=0D=0A") & ";" _
            & Replace(oContact.BusinessAddressCity & "", vbCrLf, "=0D=0A") & ";" _
            & Replace(oContact.BusinessAddressCountry & "", vbCrLf, "=0D=0A") & vbCrLf

        sVCard = sVCard & "BDAY:" & Format(oContact.Birthday, "yyyymmdd") & vbCrLf

        sVCard = sVCard & "EMAIL;PREF;INTERNET:" & oContact.Email1Address & vbCrLf

        '' Repeat as necessary for each email address
        sVCard = sVCard & "EMAIL;INTERNET:" & oContact.Email2Address & vbCrLf

        sVCard = sVCard & "ORG:" & oContact.CompanyName & ";" & oContact.Department & vbCrLf

        sVCard = sVCard & "TEL;CELL;VOICE:" & oContact.MobileTelephoneNumber & vbCrLf

        sVCard = sVCard & "TEL;HOME;FAX:" & oContact.HomeFaxNumber & vbCrLf

        sVCard = sVCard & "TEL;HOME;VOICE:" & oContact.HomeTelephoneNumber & vbCrLf

        sVCard = sVCard & "TEL;WORK;FAX:" & oContact.BusinessFaxNumber & vbCrLf

        sVCard = sVCard & "TEL;WORK;VOICE:" & oContact.BusinessTelephoneNumber & vbCrLf

        sVCard = sVCard & "TITLE:" & oContact.JobTitle & vbCrLf

        sVCard = sVCard & "URL;HOME:" & oContact.PersonalHomePage & vbCrLf

        sVCard = sVCard & "URL;WORK:" & oContact.BusinessHomePage & vbCrLf

        sVCard = sVCard & "REV:20090225T232716Z" & vbCrLf
        sVCard = sVCard & "End: VCARD"

        f.WriteLine sVCard
        f.Close
    Next

End Sub
梦屿孤独相伴 2024-08-06 10:58:07

下面是在 C# 中执行此操作的更原生方法:

using Microsoft.Office.Interop.Outlook;
using System;
using System.Collections.Generic;
using System.Text;

namespace ExportOutlookContacts
{
    class Program
    {
        static void Main(string[] args)
        {

            Items OutlookItems;
            Application outlookObj;
            MAPIFolder Folder_Contacts;

            outlookObj = new Application();
            Folder_Contacts = outlookObj.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
            OutlookItems = Folder_Contacts.Items;

            for (int i = 0; i < OutlookItems.Count; i++)
            {
                ContactItem contact = (ContactItem)OutlookItems[i + 1];
                Console.WriteLine(contact.FullName);
                // https://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.olsaveastype.aspx
                contact.SaveAs(string.Format(@"C:\TEMP\Contacts\{0}.vcf", contact.FullName), 6);
            }

            Console.WriteLine("Done!");
            Console.ReadLine();
        }
    }
}

注意: 您需要添加对 Microsoft.Office.Interop.Outlook 的引用

这会将当前 Outlook 配置文件中的所有联系人导出到多个 .VCF 文件。

顺便说一句,您可以将所有 VCF 文件合并为一个:

copy /B *.vcf CombinedContacts.vcf

这样您就可以轻松地将此文件导入到 GMail 或 iPhone。

Here is more native way to do it in C#:

using Microsoft.Office.Interop.Outlook;
using System;
using System.Collections.Generic;
using System.Text;

namespace ExportOutlookContacts
{
    class Program
    {
        static void Main(string[] args)
        {

            Items OutlookItems;
            Application outlookObj;
            MAPIFolder Folder_Contacts;

            outlookObj = new Application();
            Folder_Contacts = outlookObj.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
            OutlookItems = Folder_Contacts.Items;

            for (int i = 0; i < OutlookItems.Count; i++)
            {
                ContactItem contact = (ContactItem)OutlookItems[i + 1];
                Console.WriteLine(contact.FullName);
                // https://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.olsaveastype.aspx
                contact.SaveAs(string.Format(@"C:\TEMP\Contacts\{0}.vcf", contact.FullName), 6);
            }

            Console.WriteLine("Done!");
            Console.ReadLine();
        }
    }
}

NOTE: You need to add reference to Microsoft.Office.Interop.Outlook

This will export all contacts in the current Outlook profile to multiple .VCF files.

BTW you can combine all VCF files in one:

copy /B *.vcf CombinedContacts.vcf

This way you can easily import this file to GMail or IPhone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文