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 in Excel using Java. Furthermore, we will also generate charts based on the pivot table.

Java API to Create Pivot Table in Excel

In order to create Excel pivot table, 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.

Excel Data

Data source for excel pivot table

Pivot Table

create pivot table in excel in java

Generate a Chart using Excel Pivot Tables in Java

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

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

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