0
嗨,大家好,我可以在JACOB上只讀日曆範圍的CALENDAR文件夾,並讓我獲得主題。如果是,請給出一個示例代碼以供參考。非常感謝使用JACOB在日期範圍內閱讀日曆文件夾
嗨,大家好,我可以在JACOB上只讀日曆範圍的CALENDAR文件夾,並讓我獲得主題。如果是,請給出一個示例代碼以供參考。非常感謝使用JACOB在日期範圍內閱讀日曆文件夾
此代碼有兩個過濾器
1)首隻按日期範圍 - 開始和結束日期
2)主題=「測試」
過濾如果你只需要日期,你可以省略第二個過濾器。
How to: Filter Recurring Appointments and Search for a String in the Subject
Dispatch namespace = outlokAx.getProperty("Session").toDispatch();
Dispatch calendarFolder = Dispatch.call(namespace, "GetDefaultFolder", new Integer(9)).toDispatch();
Dispatch calItems = Dispatch.get(calendarFolder, "items").toDispatch();
String customFilter = "@SQL=\"urn:schemas:calendar:dtstart\" > '" + DateUtility.dateToUtcString(startDate) + "' and \"urn:schemas:calendar:dtend\" = '" + DateUtility.dateToUtcString(endDate) + "'" ;
String customFindFilter = "@SQL=\"urn:schemas:httpmail:subject\" like '" + "test" + "'" ;
Dispatch restrictedItems = Dispatch.call(calItems, "Restrict", new Variant(customFilter)).toDispatch(); //Works only with dates
Dispatch.call(calItems, "Sort", "[Start]");
Dispatch.put(restrictedItems, "IncludeRecurrences", "False");
int numberOfMatchingItems = 0;
Dispatch lastitemFound = null;
if (restrictedItems != null && restrictedItems.m_pDispatch > 0) {
Dispatch findItem = Dispatch.call(restrictedItems, "Find", customFindFilter).toDispatch(); // Find Works with other attributes
while (findItem != null && findItem.m_pDispatch > 0) {
numberOfMatchingItems++;
lastitemFound = findItem;
findItem = Dispatch.call(restrictedItems, "FindNext").toDispatch();
Variant start = Dispatch.get(findItem, "Start");
Variant end = Dispatch.get(findItem, "End");
Variant subject = Dispatch.get(findItem, "Subject");
System.out.println("# Outlook event fetched: " + subject + " start: '" + start + "' end '" + end + "'");
}
}