none
Populating Pivot Table in Excel in ASP.NET MVC Application using EPPlus RRS feed

  • Question

  • Hi,

    I am trying to create a pivot table from a separate sheet containing a table with columns of data. Right now, the pivot table won't populate. What am I missing here? 

    string filepath = "~\\ExportToExcel.xlsx";
    
    FileInfo newFile = new FileInfo(filepath);
    
    ExcelPackage pkg = new ExcelPackage(newFile);
    
    ExcelWorkbook excelWorkBook = pkg.Workbook;
    
    ExcelWorksheet datasheet = excelWorkBook.Worksheets[1];
    
    ExcelWorksheet pivotsheet = excelWorkBook.Worksheets.Add("Pivot Sheet");
    
    var dataRange = datasheet.Cells[datasheet.Dimension.Address];
    
    var pivotTable = pivotsheet.PivotTables.Add(pivotsheet.Cells[1,1,11,11], dataRange, "Pivot Table");
    
    pivotTable.RowFields.Add(pivotTable.Fields["field1"]);
    
    pivotTable.ColumnFields.Add(pivotTable.Fields["field2"]);
    
    pivotTable.DataFields.Add(pivotTable.Fields["field3"]);
    
    pkg.SaveAs(newFile);
    Thanks in advance

    Thursday, March 1, 2018 8:54 PM

All replies

  • Hi Hackathor,

    Based on your description, it seems your issue is related with EPPlus which is a third party product, I would suggest you go to EPPlus Offical site for help.

    They are more familari with their product.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 2, 2018 6:25 AM