This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin Cookbook and have Ken Kousen on-line!
See this thread for details.
Win a copy of Kotlin Cookbook this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Joe Ess
  • salvin francis

Convert Excel to PDF, Image, HTML, CSV, XML, XPS in Java

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this article, I will introduce how to convert an Excel file to popular file formats like PDF, Image, HTML, CSV, XML and XPS in Java using Spire.XLS for Java library.

Spire.XLS for Java is a standalone Excel library that empowers developers to create, read, edit, convert and print Excel files in Java applications without installing Microsoft Office, it supports Excel 97-2003, Excel 2007, Excel 2010, Excel 2013, Excel 2016 (.xls, .xlsx, .xlsb, .xlsm) along with Open Office(.ods) file formats.


Before getting started, please download Spire.XLS for Java package through this link, unzip the package and then import Spire.Xls.jar from lib folder into our application.

For maven projects, please add the following maven dependencies in pom.xml to import Spire.Xls.jar.

Using the code

Before coding, please add the needed namespaces as follows.

Converting Excel to PDF, XML, XPS

To convert an Excel file to PDF, XML and XPS, firstly, we need to instantiate a Workbook object and load the Excel from file using the loadFromFile(String fileName) method.

Secondly, invoking saveToFile(String fileName, FileFormat fileFormat) method to save the Excel file to PDF, XML and XPS format.

Converting Excel to Image, HTML, CSV

The code to convert Excel to Image, HTML and CSV is slightly different from the above code. After loading the Excel from file, we need to get a specific worksheet and then save the worksheet to HTML, Image and CSV.

Note if the data in 1 Excel worksheet come to 2 or more pages after converting, please add the following code to fit the data to 1 page before saving to other file formats.


Converting Excel to popular file formats is very easy with Spire.XLS for Java library. Apart from the file conversion feature, Spire.XLS for Java offers many other Excel manipulation features which are also worth trying, for example, import/export data, create chart, create pivot table, merge Excel files, print Excel files and many more.

If you have any questions, feel free to comment below or contact
Danger, 10,000 volts, very electic .... tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!