Reading MPP file columns and exporting data to XLSX (C# .NET)

Hello Team,

I am using Aspose.Tasks dll (v19.12.0) to read the mpp file and export into excel file using below code.

var prj = new Aspose.Tasks.Project(sourcePathmpp + file.Name);
prj.Save(sourcePath + @"\MSProjectfile.xlsx", Aspose.Tasks.Saving.SaveFileFormat.XLSX);

This will create three sheets Task,Resource and Assignment.

Data exported into excel file, after analysis the data we found some issues.

(1) start date and finish date ( Thu 6/01/00 Sun 2/13/00) year filed display “00” but when we open the same mpp file in Microsoft project it looks proper ( |Start|Finish| |Fri 6/1/18|Thu 2/13/20|).

(2) Missing column in the exported excel.
% Complete, Start Actual, Finish Actual, Text1, Text2, Text3,Text4,Text5, Cost, Critical
Free Slack,Number1, Number2, Number3, Number4, Number5, Start1, Start2, Finish1, Finish2.

I want to export all the data from mpp file.
how we can get all the missing column and data field year issue.
2 Exported excel.png (209.6 KB)
1 MSProjectViewer.png (223.6 KB)

Please find the attachment snapshot for more details.

Thanks,
Amit Solanki

@amitsolanki,

I have observed the issue shared by you and request you to please share the source file along with generated Excel file reproducing the issue. We will be able to proceed further with investigation on our end on provision of requested information.

Hi mudassir,
Thank for the reply.
Due to some policy, we can’t share the file.
When I read the same mpp file and create xml.
As we reading the date from xml
date format look like
2000-07-21T08:00:00
2000-07-22T08:00:00

But in the microsoft project it display like - Fri 6/1/18 and Fri 6/29/18.
How we can resolve this issue.

Please find attached screenshot.

image_2020_01_23T14_47_17_449Z-1.png (423.5 KB)
Thanks,
Amit Solanki

Hi mudassir,
I have got confirmation from authority to share the mpp file.

(1) One more think I want to ask reading mpp and generate XML took more than 15 mints, can we reduce this time?
(2) I didn’t find the relationship between task and resource how we can relate them.

Apartments.zip (2.5 MB)

Quick Summary:
(1) Date format issue in both excel and XML(XML is high priority)
(2) Missing column.
(3) Date not matched in XML.
(4) Reading mpp file and generate XML took long time .
(5)How to Map Resource and task.

Request you to please check the above issue and let me know as soon as possible.

Thanks,
Amit Solanki

Hello @amitsolanki

The presented below is a valid code sample in which we have fixed these ones

1) Date format issue in both excel and XML(XML is high priority)
(2) Missing column.
(3) Date not matched in XML.

// you need to set a valid license
// otherwise the dates in the project will be set on 2000 year
// check more details on https://docs.aspose.com/display/tasksnet/Licensing
var license = new License();
license.SetLicense(@"Aspose.Tasks.lic");

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

// you can add the columns to be exported
// as shown below
var columns = new List<ViewColumn>
{
	new GanttChartColumn("Task Mode", 50, Field.TaskManual),
	new GanttChartColumn("Id", 50, Field.TaskID),
	new GanttChartColumn("Name", 100, Field.TaskName),
	new GanttChartColumn("Start", 100, Field.TaskStart),
	new GanttChartColumn("Finish", 100, Field.TaskFinish),
	new GanttChartColumn("% Complete", 50, Field.TaskPercentComplete),
	new GanttChartColumn("Start Actual", 100, Field.TaskActualStart),
	new GanttChartColumn("Finish Actual", 100, Field.TaskActualFinish),
	new GanttChartColumn("Super Notes", 100, Field.TaskText4),
	new GanttChartColumn("Resource Names", 100, Field.TaskResourceNames),
	new GanttChartColumn("Predecessors", 50, Field.TaskPredecessors),
};
var options = new XlsxOptions
{
	View = new ProjectView(columns), 
	PresentationFormat = PresentationFormat.GanttChart
};

project.Save("TASKSNET_3798_Test.xlsx", options); 

About your latest
(5)How to Map Resource and task.

the next code sample will be helpful:

        var p = new Project();
        var task = p.RootTask.Children.Add("t");
        var r = p.Resources.Add("r");
        // here we map the resource on the task
        var resourceAssignment = p.ResourceAssignments.Add(task, r);

In concern of
(4) Reading mpp file and generate XML took long time .

We are to investigate it as soon as possible.

Hello @alexanderefremov1,

Thank you so much for quick response.
(1) Given code works for me to read the column that I wanted, and also for resource mapping.
(2) Since we don’t purchase the licence now to can’t check the date format issue.(is there a way to check for now later on we will purchase)

since we know the column list for now but for each mpp file these columns may vary.
Could you please let me know how we can identify all the column including both dynamic(Text1…, Number1…) and pre define columns (Define in Microsoft project) , so that I will read all of them and save them into the database.

My goals is to read the multiple mpp file and get all the column and save them into the database table.
Please provide a way to achieve this.

Thanks,
Amit Solanki

@amitsolanki,

if you want to test Aspose.Tasks without the evaluation version limitations, then you can request a 30-day Temporary License. Please refer to How to get a Temporary License

I suggest you to please try using following sample code:

        Project project = new Project("Apartment.mpp");
        foreach (var table in project.Tables)
        {
            foreach (var item in table.TableFields)
            {
                if (item.Title != null)//To get only renamed columns. Otherwise remove this condition
                {
                    Console.WriteLine("Field = " + item.Field);
                    Console.WriteLine("Field Title = " + item.Title);
                }
            }
        }