Help required to read Pivot Table from excel

Hey Team

Can you help me with reading excel files containing pivot tables in it?

I have Java code like this:

Worksheet sheet = worksheetscollection.get(0);
sheet1.getPivotTables().getCount() // I am getting count as '1' as there is 1 pivot table
sheet1.getPivotTables().get(0). //Now how to read this pivot table

Hi,


Thanks for your query.

Well, you need to refresh and calculate PivotTable before extracting cell values in the PivotTable report. See the sample code below that uses Enumerator (Iterator for Java) to extract cell values once the PivotTable is refreshed and data is calculated/pasted into the cells:
e.g
Sample code:

Workbook workbook = new Workbook(“Book1.xlsx”);
PivotTable table = workbook.getWorksheets().get(“Pivot”).getPivotTables().get(0);
table.refreshData();
table.calculateData();

Cells cells = workbook.getWorksheets().get(“Pivot”).getCells();
Iterator iterator = cells.iterator();
while(iterator.hasNext())
{
Cell cell = (Cell)iterator.next();
System.out.println(cell.getStringValue());

}

Hope, this helps a bit.

Thank you.

Yeah That worked like a charm . calling refreshData() , calculateData() make code working .


Thanks so much for prompt reply :slight_smile:

Hi,


That is great.
Good to know that it sorts out your issue now. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.