03.08.2016 | Daniel Weisser | comment icon 0 Comment

Simple Excel export for a Spring based web application

Have you ever had the need to provide a simple Excel export for existing data within your web application? Are you already thinking of reporting engines, complex binary formats and complicated merging of data.

This example provides a very simple example how the problem can be solved within 5 minutes.

Jxls Simple Excel reporting library

The example is based on Jxls which is a small Java library that allows for an easy Excel report generation. For simple lists of data it already has an integrated report that can be used without further customisation.

So as always first include the dependency (e.g. within a Maven based project) via

Take your data

Jxls is able to generate the report based on POJOs (or simple Entities). So just take your Spring repository or any other list of data. The example is based on a simple Person class that you can see below.

So for a Spring based example a JPARepository can be used to fetch all data from a database.

Generate the Reporting

The simplicity now is based on the fact that Jxls includes a template that generates an Excel file based on a list of data. For this list the headers must be defined, the list should be present and the names of the properties of the POJO is needed. And then simply by using the SimpleExporter an Excel file will be generated.

The result is directly written to an OutputStream and so we will directly use the functionality in a REST Controller.

Serve via a REST endpoint

So the complete example for exporting a simple Excel via and HTTP URL looks as follows.

And voila


As you can see in the screenshot a simple Excel is generated. The example can now be extended by using custom templates, more complicated data and so on.

excel export jxsl rest spring

Leave a Comment