An Interest In:
Web News this Week
- April 20, 2024
- April 19, 2024
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
March 12, 2021 08:02 am GMT
Original Link: https://dev.to/jazzzzz/create-pivot-chart-in-excel-using-java-48pi
Create Pivot Chart in Excel using Java
In my previous posts, I've introduced how to create an Excel pivot table with the 3rd party library--Free Spire.XLS for Java. This article will demonstrates how to create a pivot chart based on the data in pivot table.
Installation
Method 1: Download the Free Spire.XLS for Java and unzip it, then add the Spire.Xls.jar file to your project as dependency.
Method 2: Directly add the jar dependency to maven project by adding the following configurations to the pom.xml.
<repositories> <repository> <id>com.e-iceblue</id> <name>e-iceblue</name> <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url> </repository></repositories><dependencies> <dependency> <groupId>e-iceblue</groupId> <artifactId>spire.xls.free</artifactId> <version>3.9.1</version> </dependency></dependencies>
Java Code:
import com.spire.xls.*;import com.spire.xls.core.IPivotTable;public class CreatePivotChart { public static void main(String[] args) { //Load the Excel file Workbook workbook = new Workbook(); workbook.loadFromFile("data.xlsx"); //Get the first worksheet Worksheet sheet = workbook.getWorksheets().get(0); //get the first pivot table in the worksheet IPivotTable pivotTable = sheet.getPivotTables().get(0); //Add a clustered column chart based on the pivot table data Chart chart = sheet.getCharts().add(ExcelChartType.ColumnClustered, pivotTable); //Set chart position chart.setTopRow(14); chart.setBottomRow(25); //Set chart title chart.setChartTitle("Total"); //Save the result file workbook.saveToFile("CreatPivotChart.xlsx", ExcelVersion.Version2013); }}
Original Link: https://dev.to/jazzzzz/create-pivot-chart-in-excel-using-java-48pi
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To