Aspose.Tasks for .NET is a reliable project management API to process Microsoft Project files. API supports reading, writing and manipulating Microsoft Project documents without any other software dependencies.
Presented below is a shorthand article describing how to convert Microsoft Project files (composed in native Project formats: MPP, MS Project XML) into the non-Microsoft project formats: graphical (PNG, BMP, JPEG, TIFF, SVG, PDF), Primavera(Primavera XML, XER).
Create a new Microsoft Project document and save it to other Microsoft Project file formats
Aspose.Tasks for .NET allows to create a project from scratch and convert it into other Microsoft Project file formats (such as Microsoft Project XML, Microsoft Project MPX):
// one can create an empty project | |
var project = new Project(); | |
// or use a template file | |
var project = new Project("Microsoft Project 2019 template.mpp"); | |
var task = project.RootTask.Children.Add("Task"); | |
task.Set(Tsk.Start, new DateTime(2020, 3, 26, 8, 0, 0)); | |
task.Set(Tsk.Duration, project.GetDuration(1, TimeUnitType.Day)); | |
task.Set(Tsk.Finish, new DateTime(2020, 3, 26, 17, 0, 0)); | |
var resource = project.Resources.Add("Resource"); | |
resource.Set(Rsc.Start, new DateTime(2020, 3, 26, 8, 0, 0)); | |
resource.Set(Rsc.Finish, new DateTime(2020, 3, 26, 17, 0, 0)); | |
var resourceAssignment = project.ResourceAssignments.Add(task, resource); | |
resourceAssignment.Set(Asn.Start, new DateTime(2020, 3, 25, 8, 0, 0)); | |
resourceAssignment.Set(Asn.Work, project.GetWork(3)); | |
resourceAssignment.Set(Asn.Finish, new DateTime(2020, 3, 27, 17, 0, 0)); | |
// save as MPP file | |
project.Save("Microsoft Project 2019.mpp", SaveFileFormat.MPP); | |
// or save the project as Microsoft Project XML file | |
project.Save("Microsoft Project 2019.xml", SaveFileFormat.XML); | |
// or save the project as Microsoft Project MPX file | |
project.Save("Microsoft Project 2019.mpx", SaveFileFormat.MPX); |
Convert Microsoft Project files into graphical formats
Aspose.Tasks for .NET can read a project file from native project formats (MPP, MPX, Microsoft Project XML) and save it into any of graphical formats: PNG, BMP, JPEG, TIFF, SVG, PDF. There are two main approaches. The first allows a user to easily save a project into any of the available formats by specifying one of Aspose.Tasks.SaveFileFormat enum members:
var project = new Project("Microsoft Project 2019.mpp"); | |
// save the file as BMP | |
project.Save("Microsoft Project 2019.bmp", SaveFileFormat.BMP); | |
// or as JPEG | |
project.Save("Microsoft Project 2019.jpg", SaveFileFormat.JPEG); | |
// or as PDF file | |
project.Save("Microsoft Project 2019.pdf", SaveFileFormat.PDF); |
Another approach is a usage of special setting classes that allow to tune the saving options.
//PDF: | |
var project = new Project("Microsoft Project 2019.mpp"); | |
// let's save the project as PDF | |
// set presentation format: the view will be set to the Gantt chart | |
options.PresentationFormat = PresentationFormat.GanttChart; | |
// set the font that will be used on export | |
options.UseProjectDefaultFont = false; | |
options.DefaultFontName = "Segoe UI Black"; | |
// make the content fit in bounds of paper size (A4 by default) | |
options.FitContent = true; | |
project.Save("Microsoft Project 2019.pdf", options); |
//TIFF: | |
var project = new Project("Microsoft Project 2019.mpp"); | |
// let's save the project as TIFF | |
// create the class with image save options | |
// set the desired format into the ImageSaveOptions.#ctor | |
var options = new ImageSaveOptions(SaveFileFormat.TIFF); | |
// tune the resolutions | |
options.HorizontalResolution = 72; | |
options.VerticalResolution = 72; | |
// set the pixel format | |
options.PixelFormat = PixelFormat.Format24bppRgb; | |
// save the file as TIFF | |
project.Save("Microsoft Project 2019.tif", options); |
Convert Microsoft Project files into Primavera formats
Along with saving in graphical formats Aspose.Tasks for .NET supports conversion into Oracle Primavera formats (e.g. Primavera XML, Primavera XER):
var project = new Project("Microsoft Project 2019.mpp"); | |
// working with the project... | |
// save the project as Primavera XML file using save options | |
var options = new PrimaveraXmlSaveOptions(); | |
options.SaveRootTask = false; | |
project.Save("Microsoft Project 2019_PMXML_so.xml", options); | |
//… | |
// or save the project as Primavera XML file using SaveFileFormat | |
project.Save("Microsoft Project 2019_PMXML_sff.xml", SaveFileFormat.PrimaveraP6XML); | |
// or save the project as Primavera XER file | |
project.Save("Microsoft Project 2019_PMXML_sff.xml", SaveFileFormat.PrimaveraXER); |
Convert Microsoft Project files into other formats
Aspose.Tasks for .NET also supports a conversion of project files to HTML, XLS, XLSX, XAML, TXT formats:
//HTML: | |
var project = new Project("Microsoft Project 2019.mpp"); | |
// Save as HTML file: | |
// using SaveFileFormat | |
project.Save(OutDir + "Microsoft Project 2019 sff.html", SaveFileFormat.HTML); | |
// or using HtmlSaveOptions with desired parameters: | |
var htmlSaveOptions = new HtmlSaveOptions(); | |
// Determines whether to include project name in HTML title (true by default) | |
options.IncludeProjectNameInTitle = false; | |
// Determines whether to include project name in HTML page header (true by default) | |
options.IncludeProjectNameInPageHeader = false; | |
// set pages that will be exported | |
options.Pages = new List<int>(); | |
options.Pages.Add(1); | |
project.Save("Microsoft Project 2019 so.html", htmlSaveOptions); |
//TXT and XLSX: | |
var project = new Project("Microsoft Project 2019.mpp"); | |
// save project file as TXT file | |
project.Save(OutDir + "Microsoft Project 2019.txt", SaveFileFormat.TXT); | |
// or as XLSX file | |
project.Save(OutDir + "Microsoft Project 2019.xlsx", SaveFileFormat.XLSX); |
How to try
You can try the above-mentioned features with your projects in our free web Aspose.Tasks Conversion app - it uses the same engine under the hood.
The whole set of examples that shows the features of saving project files into various formats are in our GitHub repository. The latest version of Aspose.Tasks for .NET is always available on the official Aspose website or via NuGet package.
Top comments (0)