확장 작업 속성 사용하기
확장 작업 속성 Microsoft Project에서 사용자 정의 필드를 정의하고 작업에 대한 추가 정보를 캡처할 수 있습니다. Aspose.Tasks for .NET은 작업의 확장 속성을 다음 형식 모두에서 생성, 읽기 및 관리하는 기능을 완전히 지원합니다 MPP 및 XML 형식으로 Microsoft Project(2003–2019)의 모든 버전에서.
확장 작업 속성이란 무엇인가요?
Microsoft Project에서, Extended Attribute 는 사용자 정의 필드입니다(예: Text1, Cost2, 또는 Flag5) 표준 필드로는 다루지 못하는 비즈니스 관련 정보를 저장하는 데 사용할 수 있습니다. 이러한 속성은 다음과 같은 경우에 매우 유용합니다:
- 작업에 대한 추가 메타데이터 추적(예: 작업 분류, 위험 수준, 예산 코드).
- 보고에 필요한 프로젝트별 정보 추가.
- 전사적 프로젝트 관리 표준 적용.
Aspose.Tasks는 이 기능을 두 가지 주요 클래스를 통해 제공합니다:
- ExtendedAttributeDefinition – 사용자 정의 필드를 정의합니다(이름, 유형, 계산 규칙, 조회 값).
- ExtendedAttribute – 특정 작업에 대한 해당 사용자 정의 필드의 실제 값을 저장합니다.
작업에 확장 속성 정보 추가하기
프로그래밍으로 작업에 확장 속성을 추가하려면:
- 생성할
ExtendedAttributeDefinition
사용자 정의 필드 유형을 정의하는. - 생성할
ExtendedAttribute
해당 정의를 기반으로 한 객체를 생성합니다. - 속성을 원하는 작업에 할당합니다.
예: 확장 속성 추가
1// Create new project
2Project project = new Project("New Project.mpp");
3
4// Create an Extended Attribute Definition of Text1 type
5var taskExtendedAttributeText1Definition = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Text, ExtendedAttributeTask.Text1, "Task City Name");
6
7// Add it to the project's Extended Attributes collection
8project.ExtendedAttributes.Add(taskExtendedAttributeText1Definition);
9
10// Add a task to the project
11Task task = project.RootTask.Children.Add("Task 1");
12
13// Create an Extended Attribute from the Attribute Definition
14var taskExtendedAttributeText1 = taskExtendedAttributeText1Definition.CreateExtendedAttribute();
15
16// Assign a value to the generated Extended Attribute. The type of the attribute is "Text", the "TextValue" property should be used.
17taskExtendedAttributeText1.TextValue = "London";
18
19// Add the Extended Attribute to task
20task.ExtendedAttributes.Add(taskExtendedAttributeText1);
21
22project.Save("PlainTextExtendedAttribute_out.mpp", SaveFileFormat.MPP);
23
24Project project = new Project("New Project.mpp");
25
26// Create an Extended Attribute Definition of Text2 type
27var taskExtendedAttributeText2Definition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(CustomFieldType.Text, ExtendedAttributeTask.Text2, "Task Towns Name");
28
29// Add lookup values for the extended attribute definition
30taskExtendedAttributeText2Definition.AddLookupValue(new Value { Id = 1, StringValue = "Town1", Description = "This is Town1" });
31taskExtendedAttributeText2Definition.AddLookupValue(new Value { Id = 2, StringValue = "Town2", Description = "This is Town2" });
32
33// Add it to the project's Extended Attributes collection
34project.ExtendedAttributes.Add(taskExtendedAttributeText2Definition);
35
36// Add a task to the project
37var task2 = project.RootTask.Children.Add("Task 2");
38
39// Crate an Extended Attribute from the Text2 Lookup Definition for Id 1
40var taskExtendedAttributeText2 = taskExtendedAttributeText2Definition.CreateExtendedAttribute(taskExtendedAttributeText2Definition.ValueList[1]);
41
42// Add the Extended Attribute to task
43task2.ExtendedAttributes.Add(taskExtendedAttributeText2);
44
45project.Save("TextExtendedAttributeWithLookup_out.mpp", SaveFileFormat.MPP);
46
47Project project2 = new Project("New Project.mpp");
48
49// Create an Extended Attribute Definition of Duration2 type
50var taskExtendedAttributeDuration2Definition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(CustomFieldType.Duration, ExtendedAttributeTask.Duration2, "Some duration");
51
52// Add lookup values for extended attribute definition
53taskExtendedAttributeDuration2Definition.AddLookupValue(new Value { Id = 2, Duration = project2.GetDuration(4, TimeUnitType.Hour), Description = "4 hours" });
54taskExtendedAttributeDuration2Definition.AddLookupValue(new Value { Id = 3, Duration = project2.GetDuration(1, TimeUnitType.Day), Description = "1 day" });
55taskExtendedAttributeDuration2Definition.AddLookupValue(new Value { Id = 4, Duration = project2.GetDuration(1, TimeUnitType.Hour), Description = "1 hour" });
56taskExtendedAttributeDuration2Definition.AddLookupValue(new Value { Id = 7, Duration = project2.GetDuration(10, TimeUnitType.Day), Description = "10 days" });
57
58// Add the definition to the project's Extended Attributes collection
59project2.ExtendedAttributes.Add(taskExtendedAttributeDuration2Definition);
60
61// Add a task to the project
62var task3 = project2.RootTask.Children.Add("Task 3");
63
64// Create an Extended Attribute from the Duration2 Lookup Definition for Id 3
65var taskExtendedAttributeDuration2 = taskExtendedAttributeDuration2Definition.CreateExtendedAttribute(taskExtendedAttributeDuration2Definition.ValueList[3]);
66
67// Add the Extended Attribute to task
68task3.ExtendedAttributes.Add(taskExtendedAttributeDuration2);
69
70project2.Save("DurationExtendedAttributeWithLookup_out.mpp", SaveFileFormat.MPP);
71
72Project project3 = new Project("New Project.mpp");
73
74// Create an Extended Attribute Definition of Finish2 Type
75var taskExtendedAttributeFinish2Definition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(CustomFieldType.Finish, ExtendedAttributeTask.Finish2, "Some finish");
76
77// Add lookup values for extended attribute defintion
78taskExtendedAttributeFinish2Definition.AddLookupValue(new Value { Id = 2, DateTimeValue = new DateTime(1984, 01, 01, 00, 00, 01), Description = "This is Value2" });
79taskExtendedAttributeFinish2Definition.AddLookupValue(new Value { Id = 3, DateTimeValue = new DateTime(1994, 01, 01, 00, 01, 01), Description = "This is Value3" });
80taskExtendedAttributeFinish2Definition.AddLookupValue(new Value { Id = 4, DateTimeValue = new DateTime(2009, 12, 31, 00, 00, 00), Description = "This is Value4" });
81taskExtendedAttributeFinish2Definition.AddLookupValue(new Value { Id = 7, DateTimeValue = DateTime.Now, Description = "This is Value6" });
82
83// Add the definition to the project's Extended Attributes collection
84project3.ExtendedAttributes.Add(taskExtendedAttributeFinish2Definition);
85
86// Add a task to the project
87var task4 = project3.RootTask.Children.Add("Task 4");
88
89// Create an Extended Attribute from the Finish2 Lookup Definition for Id 3
90var taskExtendedAttributeFinish2 = taskExtendedAttributeFinish2Definition.CreateExtendedAttribute(taskExtendedAttributeFinish2Definition.ValueList[3]);
91
92// Add the Extended Attribute to task
93task4.ExtendedAttributes.Add(taskExtendedAttributeFinish2);
94
95project3.Save("FinishExtendedAttributeWithLookup_out.mpp", SaveFileFormat.MPP);
설명:
- 먼저, 우리는 Text 사용자 정의 필드(예: Text1).
- 그런 다음 우리는
ExtendedAttribute
을(를) 특정 값과 함께 인스턴스화합니다. - 마지막으로 이를 작업에 첨부하여 사용자 정의 정보를 저장할 수 있게 합니다.
확장 속성이 할당되면, 다음을 사용하여 이를 읽을 수 있습니다:
ExtendedAttributes 컬렉션입니다. 이 속성은 Task
객체 목록을 반환하며, 각 객체는 작업의 사용자 정의 필드에 대한 세부 정보를 포함합니다. ExtendedAttribute
예: 확장 속성 읽기
설명:
1Project project = new Project("New Project.mpp");
2
3// Read extended attributes for tasks
4foreach (Task task in project.RootTask.Children)
5{
6 foreach (ExtendedAttribute ea in task.ExtendedAttributes)
7 {
8 Console.WriteLine(ea.FieldId);
9 Console.WriteLine(ea.ValueGuid);
10
11 switch (ea.AttributeDefinition.CfType)
12 {
13 case CustomFieldType.Date:
14 case CustomFieldType.Start:
15 case CustomFieldType.Finish:
16 Console.WriteLine(ea.DateValue);
17 break;
18
19 case CustomFieldType.Text:
20 Console.WriteLine(ea.TextValue);
21 break;
22
23 case CustomFieldType.Duration:
24 Console.WriteLine(ea.DurationValue.ToString());
25 break;
26
27 case CustomFieldType.Cost:
28 case CustomFieldType.Number:
29 Console.WriteLine(ea.NumericValue);
30 break;
31
32 case CustomFieldType.Flag:
33 Console.WriteLine(ea.FlagValue);
34 break;
35 }
36 }
37}
각 작업은 여러 개의 확장 속성을 가질 수 있습니다.
- 이를 반복하여 사용자 정의 데이터를 추출할 수 있습니다(예: 텍스트 레이블, 숫자 값, 플래그).
- 이는 보고서, 대시보드 또는 비즈니스 로직과의 통합을 가능하게 합니다.
- 핵심 참고사항
확장 속성은 프로젝트 데이터를 사용자화할 수 있는 유연성을 제공합니다.
- 프로그래밍으로
- 정의하고, 할당하며 읽을 수 있습니다. 이
- 클래스는 사용자 정의 필드의 스키마를 정의하는 데 사용됩니다.
ExtendedAttributeDefinition
이 - 클래스는 작업별 실제 값을 저장합니다.
ExtendedAttribute
지원 대상: - 모든 주요 Microsoft Project 버전 (MPP 2003–2019) 및 XML 형식 **.**자주 묻는 질문
질문: 확장 속성에 대한 조회 테이블을 만들 수 있나요?
예. 해당 클래스는 Microsoft Project와 마찬가지로 조회 값을 지원합니다.
- 질문: 어떤 유형의 확장 속성이 지원되나요?
ExtendedAttributeDefinition
Text, Number, Cost, Flag, Date, Duration 및 Start/Finish 필드.
질문: 작업 생성 후에 확장 속성을 수정할 수 있나요?
- 물론입니다. 언제든 확장 속성을 업데이트하거나 제거할 수 있습니다.
질문: 확장 속성이 MPP/XML 파일로 저장되나요?
- 예. Aspose.Tasks는 수정된 프로젝트 파일을 저장할 때 확장 속성을 보존합니다.
질문: 이 기능은 .NET Framework와 .NET Core 모두에서 사용 가능합니까?
- 예. Aspose.Tasks for .NET은 두 플랫폼을 모두 지원합니다.
Q: Is this feature available in both .NET Framework and .NET Core?
- Yes. Aspose.Tasks for .NET supports both platforms.