Get total number of rows in a pivot

Am trying to get the total number of rows in a pivot. The following code only gives coordinatescrather than the actual number of rows:


<pre class=“lang-cs prettyprint prettyprinted” style=“margin-top: 0px; margin-bottom: 1em; padding: 5px; border: 0px; font-size: 13px; width: auto; max-height: 600px; overflow: auto; font-family: Consolas, Menlo, Monaco, “Lucida Console”, “Liberation Mono”, “DejaVu Sans Mono”, “Bitstream Vera Sans Mono”, “Courier New”, monospace, sans-serif; background-color: rgb(239, 240, 241); color: rgb(57, 51, 24); word-wrap: normal;”><code style=“margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, “Lucida Console”, “Liberation Mono”, “DejaVu Sans Mono”, “Bitstream Vera Sans Mono”, “Courier New”, monospace, sans-serif; white-space: inherit;”>var book = new Workbook(dir + “sample.xlsx”);
var sheet = book.Worksheets[0];
var pivot = sheet.PivotTables[0];

// DataBodyRange returns CellArea that represents range between the header row & insert row
var dataBodyRange = pivot.DataBodyRange;
Console.WriteLine(dataBodyRange);
// TableRange1 returns complete Pivot Table area except page fields
var tableRange1 = pivot.TableRange1;
Console.WriteLine(tableRange1);
// TableRange2 returns complete Pivot Table area including page fields
var tableRange2 = pivot.TableRange2;
Console.WriteLine(tableRange2);
// ColumnRange returns range that represents the column area of the Pivot Table
var columnRange = pivot.ColumnRange;
Console.WriteLine(columnRange);
// RowRange returns range that represents the row area of the Pivot Table
var rowRange = pivot.RowRange;
Console.WriteLine(rowRange);



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.