C# MPP-thru项目互操作中的多个筛选条件

C# MPP-thru项目互操作中的多个筛选条件,c#,ms-project,C#,Ms Project,我正在使用MS Project interop自动读取MPP。实现单列筛选器是可行的,但我只是想知道,如何使用or/add条件实现多列筛选器?我使用下面的代码来过滤单列,这是可行的: public string Load(string fileName) { MSProject.ApplicationClass app = null; try { app = new MSProject.App

我正在使用MS Project interop自动读取MPP。实现单列筛选器是可行的,但我只是想知道,如何使用or/add条件实现多列筛选器?我使用下面的代码来过滤单列,这是可行的:

public string Load(string fileName)
{
            MSProject.ApplicationClass app = null;
            try
            {
                app = new MSProject.ApplicationClass();
                app.Visible = false;

                if (app.FileOpen(fileName, true, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, MSProject.PjPoolOpen.pjPoolReadOnly, Type.Missing, Type.Missing, Type.Missing, Type.Missing))
                {
                    app.FilterEdit("My New Filter", true, true, true, Type.Missing, Type.Missing, "Resource Names", Type.Missing, "equals", "ResourceNameHere1", Type.Missing, true, true);
                    //app.FilterApply("Using Resource...", "false", "ResourceNameHere1");
                    app.SelectAll();
                    MSProject.Tasks tsk = (MSProject.Tasks)app.ActiveSelection.Tasks;
                }
            }
            catch(Exception e){}
}
问:


如何在条件中再添加一个资源名称?是否要使用and/or条件将ResourceName1与ResourceName2一起拉取,或添加条件以按完成百分比进行筛选?

更新

由于您需要摘要任务,因此创建筛选器是一个不错的选择。下面介绍如何使用3个条件创建筛选器--2个资源和完成百分比:

app.FilterEdit("My New Filter", true, true, true, Type.Missing, Type.Missing, "Resource Names", Type.Missing, "contains", "ResourceNameHere1", Type.Missing, true, true);
app.FilterEdit("My New Filter", true, false, true, Type.Missing, Type.Missing, Type.Missing, "Resource Names", "contains", "ResourceNameHere1", "Or", true, true);
app.FilterEdit("My New Filter", true, false, true, Type.Missing, Type.Missing, Type.Missing, "% Complete", "is less than", "100", "And", true, true);
先前的答案

如果目标是循环执行一组满足特定条件的任务,则无需创建过滤器、设置过滤器,然后选择所有可见的任务。以下是让您开始使用的伪代码:

For Each t In ActiveProject.Tasks
    If (t.ResourceNames Like "*Name1*" Or t.ResourceNames Like "*Name2*") And t.PercentComplete < 100 Then
        ' do something
    End If
Next t
ActiveProject.Tasks中每个t的

如果(t.ResourceNames如“*Name1*”或t.ResourceNames如“*Name2*”)和t.PercentComplete<100,则
“做点什么
如果结束
下一个t

仅供参考:若要获取对任务摘要任务的引用,请使用OutlineParent属性。

使用此方法,我将丢失摘要任务及其层次结构,因为摘要任务没有资源名称。我会吗?非常感谢。我想,你的解决方案应该行得通。当我尝试添加多个过滤器时,我也意识到了我的错误。