Hinzufügen einer neuen Aufgabe mit Aspose.Tasks vs vsto
Während der Arbeit mit Microsoft Project (MPP/XML) -Dateien müssen Sie häufig neue Aufgaben hinzufügen. Dieser Artikel zeigt, wie MPP -Dateien in Ihre .NET -Anwendungen geladen und Ihrem Projekt neue Aufgaben mit VSTO und ASSONE.TASSS FÜR .NET hinzufügen.
Fügen Sie eine Aufgabe mit VSTO hinzu
Um eine Aufgabe mit VSTO hinzuzufügen:
Erstellen Sie ein neues Projekt in Visual Studio.
Klicken Sie im Lösungs-Explorer mit der rechten Maustaste und wählen Sie Referenz hinzufügen.
Wählen Sie die Registerkarte Com -Komponenten aus und wählen Sie Microsoft -Projekt 12.0 Objektbibliothek.
Klicken Sie auf OK.
Dadurch importiert Microsoft.Office.Interop.msproject Namespace zu Beginn Ihres Codes. Verwenden Sie den Code aus dem folgenden Beispiel, um eine neue Aufgabe hinzuzufügen.
1Microsoft.office.interop.mproject.application projectApplication = new Application ();
2
3Object fissionValue = system.reflection.missing.Value;
4
5projectApplication.FileOpenex (@"C: \ project1.mpp",
6 missingValue, missingValue, missingValue, missingValue,
7
8 missingValue, missingValue, missingValue, missingValue,
9
10
11
12 missingValue, missingValue, missingValue, missingValue,
13
14 missingValue);
15
16Microsoft.Office.Interop.MSProject.Project project = projectApplication.ActiveProject;
17
18Microsoft.Office.Interop.MSProject.Task task;
19
20task = project.Tasks.Add("Task1", 1);
21
22task.Start = "8/23/2012";
23
24task.Duration = 3 * 8 * 60;
25
26task.Text1 = "Task1";
27
28projectApplication.FileCloseAll(Microsoft.Office.Interop.MSProject.PjSaveType.pjSave);
Add a Task Using Aspose.Tasks for .NET
To add tasks to project files using Aspose.Tasks for .NET:
Create a new project in Visual Studio.
In the Solution Explorer, right-click and select Add Reference.
Select .NET tab and select Aspose.Tasks.
Click OK.
This imports the Aspose.Tasks namespace at the start of your code. Use the code from the following example to add a new task.
1Project project = new Project("New Project.mpp");
2
3Task task = project.RootTask.Children.Add("Task1");
4task.Set(Tsk.ActualStart, DateTime.Parse("23-Aug-2012"));
5
6// Set duration in hours
7task.Set(Tsk.Duration, project.GetDuration(24, TimeUnitType.Hour));
8task.Set(Tsk.DurationFormat, TimeUnitType.Day);
9
10project.Save("AddNewTask_out.xml", SaveFileFormat.XML);