JanKallman / EPPlus

Create advanced Excel spreadsheets using .NET
3.76k stars 1.18k forks source link

Excel crashes after modifying source in pivot table #175

Open germanger opened 6 years ago

germanger commented 6 years ago

Issue:

Excel crashes after modifying the source data in a pivot table generated by EPPlus

Steps to reproduce it:

  1. Create two ExcelWorksheet programatically, with EPPlus

  2. Put data in the first sheet, like this:

    dataWorksheet.Cells[1, 1].Value = "Name";
    dataWorksheet.Cells[1, 2].Value = "Quantity";
    dataWorksheet.Cells[2, 1].Value = "John";
    dataWorksheet.Cells[2, 2].Value = "300";
  3. Create a PivotTable in the second sheet, make the source the first sheet, like this:

    var pivotTable = pivotWorksheet.PivotTables.Add(pivotWorksheet.Cells["A1"], dataWorksheet.Cells[1, 1, dataWorksheet.Dimension.End.Row, dataWorksheet.Dimension.End.Column], "MyPivotTable");
  4. Setup the PivotTable like this:

    pivotTable.ShowHeaders = true;
    pivotTable.UseAutoFormatting = true;
    pivotTable.ApplyWidthHeightFormats = true;
    pivotTable.ShowDrill = true;
    pivotTable.FirstHeaderRow = 1;
    pivotTable.FirstDataCol = 1;
    pivotTable.FirstDataRow = 2;
    pivotTable.DataOnRows = false;
    
    pivotTable.RowFields.Add(pivotTable.Fields["Name"]);
    pivotTable.DataFields.Add(pivotTable.Fields["Quantity"]);
  5. Open the generated Excel file, with Excel

  6. Modify the first sheet by adding a new column: "Foo"

  7. In the second sheet, select the pivot table and then "Change data source". Now expand the source so that it includes the new column "Foo"

  8. Crash! Excel has stopped working

...Any ideas on this issue?

germanger commented 6 years ago

Here's the crash

image

Any help?