수식 작업

Aspose.Tasks for .NET API는 MPP 프로젝트 파일에 수식을 읽고 쓸 수 있습니다. Formula 속성은 ExtendedAttributeDefinition 은 수식 값을 읽기 위한 인터페이스를 제공합니다. 이 문서에서는 로컬 및 Enterprise Extended Attributes에서 MPP 파일의 수식을 읽는 방법을 설명합니다. 또한 수식을 MPP 파일에 쓰는 방법도 보여줍니다.

Extended Attributes의 수식을 MPP 파일 형식에 작성하기

프로젝트에서 사용자 지정 수식을 정의하고 Extended Attributes에 할당할 수 있습니다. Aspose.Tasks는 이러한 수식을 Microsoft Project와의 호환성을 유지하면서 MPP 파일에 기록합니다.

 1Project project = new Project("New Project.mpp");
 2project.Set(Prj.NewTasksAreManual, false);
 3
 4// Create new custom field (Task Text1) with formula which will double task cost
 5ExtendedAttributeDefinition attr = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Text, ExtendedAttributeTask.Text1, "Custom");
 6attr.Alias = "Double Costs";
 7attr.Formula = "[Cost]*2";
 8project.ExtendedAttributes.Add(attr);
 9
10// Add a task
11Task task = project.RootTask.Children.Add("Task");
12
13// Set task cost
14task.Set(Tsk.Cost, 100);
15
16project.Save("WriteFormulasInExtendedAttributesToMPP_out.mpp", SaveFileFormat.MPP);

MPP 파일에서 Local 및 Enterprise Extended Attributes의 수식 읽기

Aspose.Tasks는 Local 및 Enterprise Extended Attributes 모두에 정의된 수식에 접근할 수 있도록 합니다. 이를 통해 MPP 파일에 포함된 사용자 지정 비즈니스 로직을 프로그래밍적으로 추출하고 분석할 수 있습니다.

1Project project = new Project("New Project.mpp"); // Attached test mpp
2// Read extended attribute formula
3ExtendedAttributeDefinition attr = project.ExtendedAttributes[0];
4Console.WriteLine("Attribute Formula: " + attr.Formula);

수식을 사용할 때 사용자 지정 필드 값에 대한 읽기 전용 액세스

수식이 Extended Attributes에 적용되면 결과 사용자 지정 필드 값은 읽기 전용. Aspose.Tasks는 계산된 값이 MPP 파일에 정의된 수식과 일치하도록 보장합니다.

 1// Create new project and extended attribute definition
 2Project project = new Project();
 3
 4ExtendedAttributeDefinition attribute = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Cost, ExtendedAttributeTask.Cost1, "");
 5attribute.Formula  = "[Cost]-[Actual Cost]";
 6
 7project.ExtendedAttributes.Add(attribute);
 8
 9// Add task
10Task task = project.RootTask.Children.Add("Task");
11
12// Create extended attribute
13ExtendedAttribute extendedAttribute = attribute.CreateExtendedAttribute();
14task.ExtendedAttributes.Add(extendedAttribute);
15
16// Display if extended attributes are read only or not
17Console.WriteLine(extendedAttribute.ValueReadOnly == true ? "Value is Read only" : "Value is not read only");
18extendedAttribute.NumericValue = -1000000M;
19Console.WriteLine(extendedAttribute.NumericValue == -1000000M ? "Formula values are read-only" : "Values are not read-only");
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.