最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

core api - Excel Worksheet to be updated after the pivot - Stack Overflow

programmeradmin5浏览0评论

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
        }

    }
}
发布评论

评论列表(0)

  1. 暂无评论