Java/ Convert Excel to XPS

Andrew Wilson
2 min readDec 10, 2021

XPS (XML Paper Specification) is a fixed-layout document format designed for sharing and publishing purposes. The format was originally created as an attempt to take the place of PDF file format, but it failed for a number of reasons. This article will introduce how to convert a Excel files to XPS files using Free Spire.XLS for Java.

Install Free API
Method 1: Download the Free Spire.XLS for Java and unzip it, then add the Spire.Xls.jar file to your project as dependency.

Method 2: You can also add the jar dependency to maven project by adding the following configurations to the pom.xml.

<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.xls.free</artifactId>
<version>3.9.1</version>
</dependency>
</dependencies>

Sample Code

The Workbook.saveToFile() method offered by Spire.XLS for Java enables you to easily convert Excel files to XPS with just a few lines of code. The detailed steps are as follows.

  • Create a Workbook instance.
  • Load a sample Excel document using Workbook.loadFromFile() method.
  • Save the document to XPS file format using Workbook.saveToFile() method.
import com.spire.xls.*;

public class toXPS {
public static void main(String[] args) {
//Create a Workbook instance
Workbook workbook = new Workbook();

//Load an Excel document
workbook.loadFromFile("Data.xlsx");

//Convert Excel to XPS
workbook.saveToFile("ToXPS.xps", FileFormat.XPS);
}
}

--

--

Andrew Wilson

Explore C#, Java and Python solutions for processing Word/Excel/PowerPoint/PDF files.