2017-07-07 88 views
0

我試圖創建一個VSTO外接的項目,我從以下msdn閱讀任務爲MS-項目

void Application_NewProject(Microsoft.Office.Interop.MSProject.Project pj) 
     { 
      MSProject.Task newTask = pj.Tasks.Add 
       ("This text was added by using code", missing); 
      newTask.Start = DateTime.Now; 
      newTask.Duration = "3"; 
      newTask.ResourceNames = "Rob Caron, Kelly Krout"; 
     } 

本教程在這一部分,他們教如何創建任務。現在我想從現有項目中讀取任務,但我沒有在線找到示例。我怎樣才能做到這一點?

回答

0

這是我發現閱讀任務的方式:

// Get the active project 
public static MSProject.Project ActiveProject = Globals.ThisAddIn.Application.ActiveProject; 

    // Iterating over tasks in active project 
    foreach (MSProject.Task oSubTask in ActiveProject.Tasks) 
    { 
     // Do something with the task 
    } 

    // If you want a particular task, set the index and choose the field 
    string name = ActiveProject.Tasks[1].Name;