We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Get the number of rows in a pivot

How do you get the total number of rows in a pivot, preferably without iteration? I have seen the following post but it doesn’t give a number rather it gives cell ranges:

http://stackoverflow.com/questions/40667493/how-can-i-determine-how-many-rows-a-pivottable-generates-aspose-cells

Hi,


See the sample code segment for your needs for your reference:
e.g
Sample code:

var sheet = workbook.Worksheets[0];
var pivot = workbook.Worksheets[0].PivotTables[0];
// TableRange1 returns complete Pivot Table area except page fields
var tableRange1 = pivot.TableRange1;
int sRow = tableRange1.StartRow;
int sCol = tableRange1.StartColumn;
int eRow = tableRange1.EndRow;
int eCol = tableRange1.EndColumn;

//Get total number of rows in PivotTable report.
int numRows = eRow - sRow + 1;
//Get total number of cols in PivotTable report.
int numCols = eCol - sCol + 1;

//Get the last (farthest) row index in the worksheet (general) - zero based;
int mRowIndex = sheet.Cells.MaxDataRow;

//Get the last (farthest) column index in the worksheet (general) - zero based;
int mColIndex = sheet.Cells.MaxDataColumn;

Hope, this helps a bit.

Thank you.