Working with Formulas
Contents
[
Hide
Show
]Formulas in Microsoft Project allow you to automate calculations, create custom logic, and enhance reporting capabilities.
Using Aspose.Tasks for .NET, developers can programmatically work with formulas in MPP files — from defining and editing to saving them back to the project.
This section provides an overview of how to use formulas in Aspose.Tasks, including:
- Creating and assigning formulas to custom fields.
- Reading existing formulas from MPP files.
- Working with expressions for tasks, resources, and project fields.
- Evaluating built-in and custom functions.
Getting Started
To start working with formulas in Aspose.Tasks:
- Load an existing project or create a new one.
- Access the required custom field definition.
- Assign a formula to the field.
- Save the project back to MPP format.
Example: Assigning a Formula to a Task Field
1class Program
2{
3 static void Main()
4 {
5 // Load project
6 var project = new Project("input.mpp");
7
8 // Define a custom task field
9 ExtendedAttributeDefinition attr = ExtendedAttributeDefinition.CreateTaskDefinition(
10 CustomFieldType.Number,
11 ExtendedAttributeTask.Number1,
12 "CustomFormulaField");
13
14 project.ExtendedAttributes.Add(attr);
15
16 // Assign a formula to the field
17 attr.Formula = "[Actual Duration] / [Duration]";
18
19 // Save result
20 project.Save("output.mpp", SaveFileFormat.Mpp);
21 }
22}In this example, the formula calculates a custom value based on the task’s duration and standard rate.