| This articles shows how to save project data to XLSX format using Aspose.Tasks for .NET. |
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:
- Load a Microsoft Project file.
- Save the project to XLSX using SaveFileFormat.XLSX.
Saving a Project as XLSX
The following lines of code shows how to achieve this using C# and VB.NET
C#
//Read the input Project file Project project = new Project("Project1.mpp"); //Save the Project as XLSX project.Save("Project1.XLSX", SaveFileFormat.XLSX);
Visual Basic
'Read the input Project file Dim project As New Project("Project1.mpp") 'Save the Project as SVG project.Save("Project1.XLSX", SaveFileFormat.XLSX)
Using XlsxOptions
With XlsOptions, you can modify how the project is exported.
C#
Project project = new Project("test.mpp"); XlsxOptions options = new XlsxOptions(); GanttChartColumn col = new GanttChartColumn("WBS", 100, delegate(Task task) { return task.Wbs; }); options.View.Columns.Add(col); ResourceViewColumn rscCol = new ResourceViewColumn("Cost center", 100, delegate(Resource resource) { return resource.CostCenter; }); options.ResourceView.Columns.Add(rscCol); AssignmentViewColumn assnCol = new AssignmentViewColumn("Notes", 200, delegate(ResourceAssignment assignment) { return assignment.Notes; }); options.AssignmentView.Columns.Add(assnCol); project.Save("OpenXML.xlsx", options);
Visual Basic
Dim project As New Project("test.mpp") Dim options As New XlsxOptions() Dim col As New GanttChartColumn("WBS", 100, Function(task As Task) task.Wbs) options.View.Columns.Add(col) Dim rscCol As New ResourceViewColumn("Cost center", 100, Function(resource As Resource) resource.CostCenter) options.ResourceView.Columns.Add(rscCol) Dim assnCol As New AssignmentViewColumn("Notes", 200, Function(assignment As ResourceAssignment) assignment.Notes) options.AssignmentView.Columns.Add(assnCol) project.Save("OpenXML.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.
C#
Project project = new Project("test.mpp"); project.Save("project.xml", SaveFileFormat.Spreadsheet2003);
Visual Basic
Dim project As New Project("test.mpp") project.Save("project.xml", SaveFileFormat.Spreadsheet2003)
Using Spreadsheet2003SaveOptions
Aspose.Tasks provides Spreadsheet2003SaveOptions for modifying the view data.
C#
Spreadsheet2003SaveOptions options = new Spreadsheet2003SaveOptions(); GanttChartColumn col = new GanttChartColumn("WBS", 100, delegate(Task task) { return task.Wbs; }); options.View.Columns.Add(col); ResourceViewColumn rscCol = new ResourceViewColumn("Cost center", 100,delegate(Resource resource) {return resource.CostCenter;}); options.ResourceView.Columns.Add(rscCol); AssignmentViewColumn assnCol = new AssignmentViewColumn("Notes", 200,delegate(ResourceAssignment assignment) {return assignment.Notes;}); options.AssignmentView.Columns.Add(assnCol); project.Save("project.xml", options);
Visual Basic
Dim options As New Spreadsheet2003SaveOptions() Dim col As New GanttChartColumn("WBS", 100, Function(task As Task) task.Wbs) options.View.Columns.Add(col) Dim rscCol As New ResourceViewColumn("Cost center", 100, Function(resource As Resource) resource.CostCenter) options.ResourceView.Columns.Add(rscCol) Dim assnCol As New AssignmentViewColumn("Notes", 200, Function(assignment As ResourceAssignment) assignment.Notes) options.AssignmentView.Columns.Add(assnCol) project.Save("project.xml", options)

