How to Convert Excel to XPS in Java

In this step-by-step procedure, you will learn how to convert Excel to XPS in Java. XPS is a document-sharing format similar to PDF, therefore it is very common and is required for multiple purposes. To generate XPS from Excel in Java, first load the target Excel file to a Workbook class object and then save it as an XPS file.

Steps to Convert Excel to XPS in Java

  1. Using Maven repository, add Aspose.Cells library to the project
  2. Add a reference to Workbook and SaveFormat class using the Import statement
  3. Load the source Excel file into the Workbook object for conversion to XPS
  4. Save the Excel file as XPS

In these steps, we simply install and load the required libraries into our program. After this, you have to load the target Excel file by providing its physical path or by providing it as a binary stream to the Workbook class object. Once it is loaded into the Workbook class object, you can not only save it as XPS but also to many other formats.

Code to Generate XPS from Excel in Java

In this code, we learned how does Java convert Excel to XPS, however, if you want to configure the output XPS file, you may use the XpsSaveOptions class object. This class can be used to set a variety of parameters like exporting one Excel sheet per page in XPS, the number of pages from Excel file to be saved in XPS, and many more.

If you want to convert an Excel file to any other format like PDF, you may refer to the article generate PDF from Excel in Java. This conversion of Excel to XPS in Java does not require any third-party tool, Interop, or installation of MS Excel on the system where this operation is performed.