java 导入outlook联系人,JAVA JACOB Outlook获取所有联系人

I´m developing an JAVA application which gets all contacts from Outlook via the JACOB Java Com Bridge. In Outlook there is the standard folder "Meine Kontakte" / "My Contacts" and the related sub folder "Kontakte" / "Contacts". So everything works fine and i´m getting all the contacts. But when i create another sub folder, for example "Test", the contacts inside this folder will not be shown in my JAVA application. It seems that only the contacts in the default folder will be fetched... But i need all the contacts. Does anyone know a solution?

Here is the code:

final int olFolderContacts = 10;

contact = new Vector();

ActiveXComponent ol = new ActiveXComponent("Outlook.Application");

@SuppressWarnings("unused")

Dispatch dsp = new Dispatch();

Dispatch olo = ol.getObject();

Dispatch myNamespace = Dispatch.call(olo, "GetNamespace", "MAPI")

.toDispatch();

Dispatch myFolder = Dispatch.call(myNamespace, "GetDefaultFolder",

new Integer(olFolderContacts)).toDispatch();

Dispatch items = Dispatch.get(myFolder, "Items").toDispatch();

int count = Dispatch.call(items, "Count").toInt();

for (int i = 1; i <= count; i++) {

Dispatch item;

item = Dispatch.call(items, "Item", new Integer(i)).toDispatch();

String fullName = Dispatch.get(item, "Fullname").toString();

String birthday = Dispatch.get(item, "Birthday").toString();

System.out.print(fullName);

DateFormat dateFormat = new SimpleDateFormat(

"EEE MMM dd HH:mm:ss Z yyyy");

Calendar cal_current = Calendar.getInstance();

// Calendar birthday !!!

Calendar cal = Calendar.getInstance();

SimpleDateFormat sdf = new SimpleDateFormat(

"EEE MMM dd HH:mm:ss Z yyyy", Locale.ENGLISH);

try {

cal.setTime(sdf.parse(birthday));

} catch (ParseException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

@SuppressWarnings("unused")

int monthCurrent = cal_current.get(Calendar.MONTH);

@SuppressWarnings("unused")

int month = cal.get(Calendar.MONTH);

....

解决方案

Ok, here is the solution. You have to call the specific inner/sub folder.

Thanks for your help!

Dispatch innerFolder = Dispatch.call(myFolder, "Folders","Test").toDispatch();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值