Convert Project Data to Excel in C++

This article demonstrates how to save project data to XLSX format using Aspose.Tasks for C++.

The Project class exposes the Save method which is used to save a project in various formats. The Save method allows you to save project tasks, resources and assignments to separate worksheets to XLSX format using the SaveFileFormat enumeration type.

To save a project to XLSX:

  1. Load a Microsoft Project file.
  2. Save the project to XLSX using SaveFileFormat.XLSX.

Saving a Project as XLSX

The following lines of code demonstrate how to achieve this using C++.

1// Read the input Project file
2System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
3    
4// Save the Project as XLSX
5project->Save(dataDir + u"SaveProjectAsXLSX_out.xlsx", Aspose::Tasks::Saving::SaveFileFormat::XLSX);

Using XlsxOptions

With XlsxOptions, you can modify how the project is exported.

 1// Read the input Project file
 2System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
 3    
 4System::SharedPtr<XlsxOptions> options = System::MakeObject<XlsxOptions>();
 5    
 6// Add desired Gantt Chart columns
 7System::SharedPtr<GanttChartColumn> col = System::MakeObject<GanttChartColumn>(u"WBS", 100, &UsingXlsxOptions::_anonymous_method_0);
 8options->get_View()->get_Columns()->Add(col);
 9    
10// Add desired resource view columns
11System::SharedPtr<ResourceViewColumn> rscCol = System::MakeObject<ResourceViewColumn>(u"Cost center", 100, &UsingXlsxOptions::_anonymous_method_1);
12options->get_ResourceView()->get_Columns()->Add(rscCol);
13    
14// Add desired assignment view columns
15System::SharedPtr<AssignmentViewColumn> assnCol = System::MakeObject<AssignmentViewColumn>(u"Notes", 200, &UsingXlsxOptions::_anonymous_method_2);
16options->get_AssignmentView()->get_Columns()->Add(assnCol);
17    
18project->Save(dataDir + u"UsingXlsxOptions_out.xlsx", options);

Save Project Data to Spreadsheet2003 XML

There are two ways to save data to Spreadsheet2003 XML format: default, or using save options. Using the SaveFileFormat instance, the default view data is saved.

1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
2project->Save(dataDir + u"SaveProjectDataToSpreadsheet2003XML_out.xml", Aspose::Tasks::Saving::SaveFileFormat::Spreadsheet2003);

Using Spreadsheet2003SaveOptions

Aspose.Tasks for C++ provides Spreadsheet2003SaveOptions for modifying the view data.

 1System::SharedPtr<Spreadsheet2003SaveOptions> options = System::MakeObject<Spreadsheet2003SaveOptions>();
 2System::SharedPtr<GanttChartColumn> col = System::MakeObject<GanttChartColumn>(u"WBS", 100, &UsingSpreadsheet2003SaveOptions::_anonymous_method_0);
 3options->get_View()->get_Columns()->Add(col);
 4    
 5System::SharedPtr<ResourceViewColumn> rscCol = System::MakeObject<ResourceViewColumn>(u"Cost center", 100, &UsingSpreadsheet2003SaveOptions::_anonymous_method_1);
 6options->get_ResourceView()->get_Columns()->Add(rscCol);
 7    
 8System::SharedPtr<AssignmentViewColumn> assnCol = System::MakeObject<AssignmentViewColumn>(u"Notes", 200, &UsingSpreadsheet2003SaveOptions::_anonymous_method_2);
 9options->get_AssignmentView()->get_Columns()->Add(assnCol);
10    
11project->Save(dataDir + u"UsingSpreadsheet2003SaveOptions_out.xml", options);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.