プロジェクトの Extended Attributes の操作

Microsoft Projectは、 拡張可能な XML データスキーマ で、アプリケーション間のスムーズなデータ交換を可能にし、プロジェクト情報のカスタマイズに強力なオプションを提供します。その最も柔軟な機能の一つは Extended Attributesで、ユーザーはタスク、リソース、および割り当てにカスタムフィールドを追加できます。これらのカスタムフィールドは、コストコード、リスクカテゴリ、承認状態、または組織が必要とするその他の分類などの業務固有のメタデータを格納するためによく使用されます。 Aspose.Tasks for .NETを使用すると、開発者はプログラムで extended attributes を作成、読み取り、更新、保存できます (Microsoft Project をインストールする必要はありません)。これによりワークフローの自動化、カスタム情報によるプロジェクトデータの強化、Microsoft Project ファイルをより広範なエンタープライズシステムへ統合することが可能になります。

Microsoft Project を使用した Custom Fields の操作

この例では、プロジェクトの情報を Task に関連付けるために Text1 extended attribute を操作する方法を示します。

  1. MSP で、 Project → Custom Fields
  2. ここから、 Task
  3. 選択して、 Text を Type コンボボックスから Custom Field Type として選択します。
  4. 選択して、 Text1 を操作したいカスタムフィールドとして選択します。
  5. を使用して、 Rename ボタンでフィールドの別名を必要に応じて変更し、次に OKを押します。
  6. 新しいタスクを追加し、タスク行にカスタムフィールドの列を挿入します。

Microsoft Projectでextended attributesを開く

Aspose.Tasks for .NET を使用した Custom Fields/Extended Attributes の操作

Aspose.Tasks for .NET API は、新しい extended attributes を作成する機能と、既存ドキュメント内の Extended attributes を操作する機能を提供します。カスタムフィールドまたは Extended Attributes は、Aspose.Tasks のプロジェクトの ExtendedAttributes コレクションで表されます。これはプロジェクトドキュメントのすべての extended attributes 定義を含みます。MSP の Custom Field 定義のいくつかのマッピングは、以下の図のようになっています。

Microsoft Project における extended attributes の切り替え

新しい Extended Attribute を作成して Task に追加する

タスクまたはリソース用の新しい extended attribute を追加するには、まず extended attribute 定義を定義して ExtendedAttributes コレクションに追加する必要があります。 ExtendedAttributeDefinition クラスはプロジェクト内で新しい ExtendedAttribute を定義するために使用されます。適切に Extended attribute を定義するには FieldId を設定する必要があり、それは次にリンクされます: ExtendedAttributeTask (Task の場合)または ExtendedAttributeResource (Resource の場合)。以下のサンプルコードは、プロジェクトの Text1 フィールドの新しい Extended Attribute を定義する方法を示します。Extended Attribute の定義が完了したら、そこから新しい Extended Attribute を作成し、それをタスクに割り当てることができます。

 1Project project = new Project("New Project.mpp");
 2
 3ExtendedAttributeDefinition myTextAttributeDefinition = project.ExtendedAttributes.GetById((int)ExtendedAttributeTask.Text1);
 4
 5// If the Custom field doesn't exist in Project, create it
 6if (myTextAttributeDefinition == null)
 7{
 8    myTextAttributeDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Text1, "My text field");
 9    project.ExtendedAttributes.Add(myTextAttributeDefinition);
10}
11
12// Generate Extended Attribute from definition
13ExtendedAttribute text1TaskAttribute = myTextAttributeDefinition.CreateExtendedAttribute();
14
15text1TaskAttribute.TextValue = "Text attribute value";
16
17// Add extended attribute to task
18Task task = project.RootTask.Children.Add("Task 1");
19task.ExtendedAttributes.Add(text1TaskAttribute);
20
21project.Save("CreateExtendedAttributes_out.mpp", SaveFileFormat.MPP);

更新された Extended Attribute の定義と値を MPP に書き込む

Aspose.Tasks for .NET は Microsoft Project の MPP ファイル内の extended attribute データを更新し、保存することをサポートします。

以下のサンプルコードは、次のタイプの新しい extended attributes をソース MPP ファイルに追加します: Resource および Task タイプをソース MPP ファイルに追加します。この操作に含まれる手順は次のとおりです:

  1. 次のインスタンスを作成します: Project Reader
  2. ソース MPP ファイルを読み込みます。
  3. 新しい extended attribute を定義し、その値を更新します。
  4. プロジェクトを次を使用して保存します: Project Writer

以下の例は、リソースの extended attributes を設定する方法を示します。

  1Project project = new Project("New Project.mpp");
  2
  3// Add new text3 extended attribute with lookup and one lookup value
  4ExtendedAttributeDefinition taskTextAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Text3, "New text3 attribute");
  5taskTextAttributeDefinition.ElementType = ElementType.Task;
  6project.ExtendedAttributes.Add(taskTextAttributeDefinition);
  7
  8Value textVal = new Value();
  9textVal.Id = 1;
 10textVal.Description = "Text value descr";
 11textVal.Val = "Text value1";
 12
 13taskTextAttributeDefinition.AddLookupValue(textVal);
 14
 15// Add new cost1 extended attribute with lookup and two cost values
 16ExtendedAttributeDefinition taskCostAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Cost1, "New cost1 attribute");
 17project.ExtendedAttributes.Add(taskCostAttributeDefinition);
 18
 19Value costVal1 = new Value();
 20costVal1.Id = 2;
 21costVal1.Description = "Cost value 1 descr";
 22costVal1.Val = "99900";
 23
 24Value costVal2 = new Value();
 25costVal2.Id = 3;
 26costVal2.Description = "Cost value 2 descr";
 27costVal2.Val = "11100";
 28
 29taskCostAttributeDefinition.AddLookupValue(costVal1);
 30taskCostAttributeDefinition.AddLookupValue(costVal2);
 31
 32// Add new task and assign attribute lookup value.
 33Task task = project.RootTask.Children.Add("New task");
 34
 35ExtendedAttribute taskAttr = taskCostAttributeDefinition.CreateExtendedAttribute(costVal1);
 36task.ExtendedAttributes.Add(taskAttr);
 37
 38ExtendedAttributeDefinition taskStartAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Start7, "New start 7 attribute");
 39
 40Value startVal = new Value();
 41startVal.Id = 4;
 42startVal.DateTimeValue = DateTime.Now;
 43startVal.Description = "Start 7 value description";
 44
 45taskStartAttributeDefinition.AddLookupValue(startVal);
 46
 47project.ExtendedAttributes.Add(taskStartAttributeDefinition);
 48
 49ExtendedAttributeDefinition taskFinishAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Finish4, "New finish 4 attribute");
 50
 51Value finishVal = new Value();
 52finishVal.Id = 5;
 53finishVal.DateTimeValue = DateTime.Now;
 54finishVal.Description = "Finish 4 value description";
 55
 56taskFinishAttributeDefinition.ValueList.Add(finishVal);
 57
 58project.ExtendedAttributes.Add(taskFinishAttributeDefinition);
 59
 60ExtendedAttributeDefinition numberAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Number20, "New number attribute");
 61
 62Value val1 = new Value();
 63val1.Id = 6;
 64val1.Val = "1";
 65val1.Description = "Number 1 value";
 66Value val2 = new Value();
 67val2.Id = 7;
 68val2.Val = "2";
 69val2.Description = "Number 2 value";
 70Value val3 = new Value();
 71val2.Id = 8;
 72val3.Val = "3";
 73val3.Description = "Number 3 value";
 74
 75numberAttributeDefinition.AddLookupValue(val1);
 76numberAttributeDefinition.AddLookupValue(val2);
 77numberAttributeDefinition.AddLookupValue(val3);
 78
 79project.ExtendedAttributes.Add(numberAttributeDefinition);
 80
 81ExtendedAttributeDefinition resourceStartAttributeDefinition = ExtendedAttributeDefinition.CreateLookupResourceDefinition(ExtendedAttributeResource.Start5, "New start5 attribute");
 82
 83Value startVal2 = new Value();
 84startVal2.Id = 9;
 85startVal2.DateTimeValue = DateTime.Now;
 86startVal2.Description = "this is start5 value descr";
 87
 88resourceStartAttributeDefinition.AddLookupValue(startVal2);
 89
 90project.ExtendedAttributes.Add(resourceStartAttributeDefinition);
 91
 92// Define a duration attribute without lookup.
 93ExtendedAttributeDefinition taskDurationAttributeDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Duration1, "New Duration");
 94project.ExtendedAttributes.Add(taskDurationAttributeDefinition);
 95
 96// Add new task and assign duration value to the previously defined duration attribute.
 97Task timeTask = project.RootTask.Children.Add("New task");
 98
 99ExtendedAttribute durationExtendedAttribute = taskDurationAttributeDefinition.CreateExtendedAttribute();
100
101durationExtendedAttribute.DurationValue = project.GetDuration(3.0, TimeUnitType.Hour);
102timeTask.ExtendedAttributes.Add(durationExtendedAttribute);
103
104MPPSaveOptions mppSaveOptions = new MPPSaveOptions();
105mppSaveOptions.WriteViewData = true;
106
107project.Save("WriteUpdatedExtendedAttributeDefinitions_out.mpp", mppSaveOptions);

Extended Attributes は、組織が必要とする カスタムプロジェクトメタデータ を Microsoft Project の組み込みフィールドを越えて扱うために重要な機能です。これらは、財務識別子の追跡からワークフロー承認の記録まで、特定の業務ニーズにプロジェクトファイルを適応させる柔軟性を提供します。 Aspose.Tasks for .NETを活用することで、開発者は extended attributes の作成と管理を完全に自動化できます。これによりエンタープライズシステム全体で一貫性があり信頼でき、標準準拠のデータ処理が保証されます。この機能は、手動操作なしで Microsoft Project のデータをレポーティングパイプライン、ERP システム、その他のアプリケーションへ統合するのに役立ちます。

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.