Outlook + Perl + Win32 :: Ole:如何选择按日期排序的日历项?
时间:2020-03-05 18:57:39 来源:igfitidea点击:
当前代码打开一个Outlook Calendar数据库,如下所示:
my $outlook = Win32::OLE->GetActiveObject('Outlook.Application') || Win32::OLE->new('Outlook.Application', 'Quit'); my $namespace = $outlook->GetNamespace("MAPI"); ## only fetch entries from Jan 1, 2007 onwards my $restrictDates = "[Start] >= '01/01/2007'";
解决方案
回答
由于我们没有显示获取对象日期的代码,因此,如果不了解我们要访问的Outlook对象,就无法回答此问题。
如果我们有一组对象,则可以按日期对它们进行排序,并过滤某个对象之前的对象。
my $sub = sub { my $ad = $a->date_string_accessor; my $bd = $b->date_string_accessor; $ad =~ s:(\d+)/(\d+)/(\d+): . sprintf('%0d', ) . sprintf('%0d', ):e; $bd =~ s:(\d+)/(\d+)/(\d+): . sprintf('%0d', ) . sprintf('%0d', ):e; return $ad cmp $bd; }; my @sorted = sort $sub @unsorted; print join("\n", @sorted);
但是在我看来,我们应该使用应用程序本身来执行此操作-大概Outlook具有某种查询/排序功能。