Customize MS Project Resource View Columns in Aspose.Tasks

Introduction

Aspose.Tasks for .NET is a powerful API that allows developers to work with Microsoft Project files programmatically. One common task in project management is customizing views to display specific information. In this tutorial, we will explore how to customize MS Project resource view columns using Aspose.Tasks for .NET.

Prerequisites

Before we begin, make sure you have the following:

  1. Aspose.Tasks for .NET Library: You can download it from here.
  2. Microsoft Project File: Have a sample MS Project file handy for testing.
  3. Development Environment: A development environment set up with .NET framework.

Import Namespaces

First, let’s import the necessary namespaces to our project:

using Aspose.Tasks;
using System;
using System.Collections.Generic;
using System.Globalization;

using Aspose.Tasks.Saving;
using Aspose.Tasks.Visualization;

Step 1: Load the Project File

Load the MS Project file using Aspose.Tasks API:

var project = new Project("Your_Project_File_Path.mpp");

Step 2: Get Resource and Define Options

Next, get the resource whose view columns you want to customize and define the PDF save options:

var resource = project.Resources.GetById(1);
var options = new PdfSaveOptions();

Step 3: Define Custom Columns

Now, define custom columns for the resource view. You can specify various fields and even use delegates for custom calculations:

var columns = new List<ViewColumn>
{
    new ResourceViewColumn(100, Field.ResourceName),
    new ResourceViewColumn(100, Field.ResourceActualWork),
    new ResourceViewColumn(100, Field.ResourceCost),
    new ResourceViewColumn(
        "Resource Cost2", 
        80,
        delegate(Resource res)
        {
            return res.Get(Rsc.Cost).ToString(CultureInfo.InvariantCulture);
        }),
    new ResourceViewColumn(
        "Resource Cost2", 
        80,
        delegate(Resource res)
        {
            return res.Get(Rsc.Cost).ToString(CultureInfo.InvariantCulture);
        }, 
        Field.ResourceCost2)
};

Step 4: Iterate Over Columns

Iterate over the defined columns and display their properties:

foreach (var column in columns)
{
    var col = (ResourceViewColumn)column;
    Console.WriteLine("Column Name: " + col.Name);
    Console.WriteLine("Column Field: " + col.Field);
    Console.WriteLine("Column Text: " + col.GetColumnText(resource));
    Console.WriteLine();
}

Step 5: Save the Customized View

Finally, set the custom view and save it as a PDF file:

options.View = new ProjectView(columns);
options.PresentationFormat = PresentationFormat.ResourceUsage;
project.Save("Output_PDF_File_Path.pdf", options);

By following these steps, you can efficiently customize MS Project resource view columns using Aspose.Tasks for .NET.

Conclusion

Customizing MS Project resource view columns is essential for displaying relevant information tailored to your project’s needs. With Aspose.Tasks for .NET, this task becomes straightforward and efficient, allowing you to create customized views effortlessly.

FAQ’s

Can I customize views for other elements besides resources?

Yes, Aspose.Tasks allows customization for tasks, assignments, and other project elements as well.

Does Aspose.Tasks support saving views in formats other than PDF?

Yes, you can save views in various formats such as XLSX, HTML, and images.

Is it possible to apply formatting to the custom view?

Absolutely, Aspose.Tasks provides extensive formatting options to enhance the appearance of your customized views.

Can I dynamically update the custom view based on changing project data?

Yes, you can update and regenerate the custom view whenever the underlying project data changes.

Does Aspose.Tasks support cross-platform development?

Aspose.Tasks for .NET primarily targets .NET platforms, but there are also versions available for Java and other platforms.