XAML (Extensible Application Markup Language) is a simple and declarative language based on XML. It is a Microsoft variant of XML to define UI elements, data binding, and events. It enables creating, initializing, and setting the properties of objects with hierarchical relations. XAML is mainly used to create GUI in WPF (Windows Presentation Foundation), Silver light, WF (Workflow Foundation), Win UI (Windows UI Library), UWP (Universal Windows Platform), and Xamarin Forms. In this article, we will learn how to convert Microsoft Project data to XAML using Java.
The following topics shall be covered in this article:
- Java API to Convert Project Data to XAML
- Export Project Data to XAML
- Convert MPP to XAML with Additional Options
- Convert MPP to XAML with Presentation Format
Java API to Convert Project Data to XAML
For converting MS Project data from MPP to XAML, we will be using the Aspose.Tasks for Java API. It allows creating, editing, or manipulating of Microsoft Project files (MPP, MPT, MPX, and XML) programmatically. The Project class of the API represents a project and exposes various methods to perform different functions. The XamlOptions class allows specifying additional options while rendering project pages to XAML.
Please either download the JAR of the API or add the following pom.xml configuration in a Maven-based Java application.
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>http://repository.aspose.com/repo/</url>
</repository>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-tasks</artifactId>
<version>22.5</version>
<classifier>jdk18</classifier>
</dependency>
Export Project Data to XAML in Java
We can easily export project data from an MPP file to XAML format by following the steps given below:
- Load the MPP file using the Project class.
- Save the XAML file using the save() method. It takes the file path and SaveFileFormat as arguments.
The following sample code shows how to convert MPP files to XAML format in Java.
Convert MPP to XAML with Additional Options in Java
We can define XamlOptions like FitContent, LegendOnEachPage, TimeScale, and View while converting MPP to XAML. We can convert the MPP file to XAML with additional options by following the given below steps:
- Firstly, load the MPP file using the Project class.
- Next, create an instance of the XamlOptions class.
- After that, set the desired options.
- Finally, save the XAML file using the save() method. It takes the file path and SaveFileFormat as arguments.
The following sample code shows how to convert the MPP file to XAML format with additional options in Java.
Convert MPP to XAML with Presentation Format in Java
We can use different presentation formats while converting MPP files to XAML format. The PresentationFormat enumeration of the API provides the following options.
- GanttChart - Gantt Chart presentation format.
- TaskUsage - Task usage presentation format.
- ResourceUsage - Resource usage presentation format.
- ResourceSheet - Resource sheet presentation format.
- TaskSheet - Task sheet presentation format.
We can set the presentation format and then convert the MPP file to XAML by following the steps given below:
- Firstly, load the MPP file using the Project class.
- Next, create an instance of the XamlOptions class.
- After that, set the presentation format using the setPresentationFormat().
- Finally, save the XAML file using the save() method. It takes the file path and SaveFileFormat as arguments.
The following sample code shows how to set the presentation format and convert the MPP file to XAML using Java.
Get a Free License
You can get a free temporary license to try the library without evaluation limitations.
Conclusion
In this article, we have learned how to load and convert MS Project (MPP) files to XAML in Java. We have also seen how to set XAML save options while exporting project data from MPP to XAML. Besides, you can learn more about Aspose.Tasks for Java API using the documentation. In case of any ambiguity, please feel free to contact us on the forum.