Create Pivot Tables in Excel using Java

Pivot tables in Excel spreadsheets are used to summarize the data in an interactive way. Suppose, you have the data of a number of invoices in a worksheet. In that case, you can use a pivot table to total the invoices grouped by the customers or products. In this article, you will learn how to deal with pivot tables in Excel programmatically. Particularly, you will come to know how to create a pivot table and generate a chart based on that pivot table in Java.

Java API to Work with Excel Pivot Tables

In order to work with Excel pivot tables, we’ll use Aspose.Cells for Java. It is a powerful API that lets you generate, modify and convert Excel files from within your Java applications. You can either download the API or install it using the following Maven configurations.

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
</repository>
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-cells</artifactId>
    <version>21.4</version>
</dependency>

Create a Pivot Table in Excel using Java

The following are the steps to create a pivot table in Excel using Java.

The following code sample shows how to add a pivot table in Excel using Java.

Excel Data

Data source for excel pivot table

Pivot Table

create pivot table in excel in java

Generate a Chart using Excel Pivot Table in Java

The following are the steps to generate a chart using Excel pivot table in Java.

The following code sample shows how to generate a chart using an Excel pivot table in Java.

Get a Free API License

You can get a free temporary license to use the API without evaluation limitations.

Conclusion

In this article, you have learned how to create a pivot table in Excel using Java. Furthermore, you have seen how to generate charts using the pivot tables in Excel. You can explore more about Java Excel API using documentation. In case you would have any questions, feel free to let us know via our forum.

See Also