Is it possible to create Pivot Chart with source data as Pivot Table using Apache POI

0 votes
Using apache POI separately, I can make a pivot table and a pivot chart. However, rather than starting with data from a sheet, I'm trying to generate a column chart from a pivot table. I tried searching for advice here but was unsuccessful. If you can, will you kindly point me in the appropriate direction?
Dec 15, 2022 in Others by Kithuzzz
• 38,000 points
800 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

It is as simple as adding a pivot source to the chart for use with Microsoft Excel. Excel then creates the chart using the provided pivot table.

The qualified name of the pivot table is set as the name of the PivotSource element in Office Open XML (XSSF), which provides the pivot source. [WorkbookName] is an acceptable name. worksheetName!pivotTableName.

This is the name of the worksheet in square brackets, followed by an exclamation point, the name of the pivot table, and then the name of the workbook.

In code this would look as so:

...
String pivotTableName = pivotTable.getCTPivotTableDefinition().getName();
String qualifiedPivotSourceName = "[" + workbookName + "]" + pivotSheet.getSheetName() + "!" + pivotTableName;
chart.getCTChartSpace().addNewPivotSource().setName(qualifiedPivotSourceName);
...
    

Using that one does not even need to set the source data range in the chart as excel takes it from the given pivot table. So only dummy data would be given as so:

...
XDDFDataSource<String> countries = XDDFDataSourcesFactory.fromArray(new String[]{"dummy"});
XDDFNumericalDataSource<Double> values = XDDFDataSourcesFactory.fromArray(new Double[]{1d});
...
answered Dec 16, 2022 by narikkadan
• 63,600 points

edited Mar 5

Related Questions In Others

0 votes
1 answer

How to create page borders using Apache POI in excel files with Java?

Microsoft Excel cannot do this. Libreoffice Calc ...READ MORE

answered Dec 13, 2022 in Others by narikkadan
• 63,600 points
1,338 views
0 votes
1 answer

Is there a way to hide excel formula using Apache POI

In Excel, hiding formulae is a feature ...READ MORE

answered Oct 11, 2022 in Others by narikkadan
• 63,600 points
1,444 views
0 votes
1 answer

How to create a dependent drop down list using [Apache POI]

There is nothing apache poi cannot do, ...READ MORE

answered Oct 24, 2022 in Others by narikkadan
• 63,600 points
6,274 views
0 votes
1 answer

Use Excel pivot table as data source for another Pivot Table

Press the keys Alt+D+P in a new ...READ MORE

answered Nov 11, 2022 in Others by narikkadan
• 63,600 points
15,413 views
0 votes
1 answer

Is it possible to get data from a webpage in real-time to an excel file?

The conventional method of obtaining data from ...READ MORE

answered Jan 17, 2023 in Others by narikkadan
• 63,600 points
647 views
0 votes
1 answer
0 votes
1 answer

Can anyone show how to modify an existing excel sheet using Apache POI?

Hello Prakash, to modify an existing excel ...READ MORE

answered Jul 17, 2019 in Selenium by Anvi
• 14,150 points
3,935 views
0 votes
1 answer

How can I read numeric data from an Excel sheet using Selenium Webdriver?

Hey Jignesh, for reading numeric data from ...READ MORE

answered Jul 17, 2019 in Selenium by Abha
• 28,140 points
8,411 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP