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. Regardless, the XPS file format is still being used in some occasions, and sometimes you may need to convert your Excel files to XPS files. This article will introduce how to accomplish this task using Spire.XLS for Java.
Install Spire.XLS for Java
First of all, you're required to add the Spire.Xls.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.
<repositories> <repository> <id>com.e-iceblue</id> <name>e-iceblue</name> <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url> </repository> </repositories> <dependencies> <dependency> <groupId>e-iceblue</groupId> <artifactId>spire.xls</artifactId> <version>14.8.2</version> </dependency> </dependencies>
Convert Excel to XPS
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.
- Java
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("test.xlsx"); //Convert Excel to XPS workbook.saveToFile("ToXPS.xps", FileFormat.XPS); } }
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.