Using Syncfusion.XlsIO excel engine in the below code after updated the pivot table the worksheet still has the old data, usedRange.LastRow has 25 rows where as my original excel has 100 rows after pivot update
IApplication application = excelEngine.Excel;
FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite);
IWorkbook xlworkbook = application.Workbooks.Open(fileStream);
IWorksheet oreportSheet = xlworkbook.Worksheets["Report"];
if (pivotTables.Count > 0)
{
IPivotTable pivotTable = oreportSheet.PivotTables[0];
PivotTableImpl pivotTableImpl = pivotTable as PivotTableImpl;
//Refreshing pivot cache to update the pivot table
pivotTableImpl.Cache.IsRefreshOnLoad = true;
}
IRange usedRange = oreportSheet.UsedRange;
for (int row = 1; row <= usedRange.LastRow; row++)
{
for (int column = 1; column <= usedRange.LastColumn; column++)
{
try
{
IRange cell = oreportSheet[row, column];
string sValue = cell.Value;
// Do something with the cell value
if (!String.IsNullOrEmpty(sValue))
{
if (sValue.Equals("(blank) Sum") || sValue.Equals("(blank) Count") || sValue.Equals("(blank) Average") || sValue.Equals("(blank)"))
{
// oreportSheet.SetRowHeight(row, 0);// oreportSheet.ShowRow(row, false);
oreportSheet.HideRow(row);
break;
}
}
}
catch (System.Exception ex)
{
// Handle the exception
}
}
}