title: OfficeOpenXML EPPlus in C# - Excel file becomes corrupt after a certain size of data is written to it
body: <p>I am using the <code>OfficeOpenXML</code> library to export excel data in my <code>.NET MVC</code> Application. However I noticed something funny going on. I am able to download the file but when opening it I am prompted with the following message. If I hit "Yes" all the data is shown without any issues. </p>
  
  <p>I noticed this prompt only shows up after a certain amount of data is written to the excel file. And not a huge amount. If I write 1000 rows of data as shown below the prompt shows, but 10 rows it doesn't show. </p>
  
  <p><a href="https://i.stack.imgur.com/vc0ix.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vc0ix.png" alt="enter image description here"></a></p>
  
  <p>Code below:</p>
  
  <pre><code>public static ExcelPackage GenerateExcelFile&lt;T&gt;(ExcelPackage pck)
  {
      ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Data");
      DataTable dt = new DataTable();
  
      dt.Columns.Add(new DataColumn { ColumnName = "A" });
      dt.Columns.Add(new DataColumn { ColumnName = "B" });
      dt.Columns.Add(new DataColumn { ColumnName = "C" });
      dt.Columns.Add(new DataColumn { ColumnName = "D" });
      dt.Columns.Add(new DataColumn { ColumnName = "E" });
  
      for (int i = 0; i &lt; 1000; i++)
      {
          DataRow row = dt.NewRow();
          row["A"] = "Value";
          row["B"] = "Value";
          row["C"] = "Value";
          row["D"] = "Value";
          row["E"] = "Value";
          dt.Rows.Add(row);
      }
      ws.Cells["A1"].LoadFromDataTable(dt, true);
      return pck;
  }
  </code></pre>
  
  <p>This is taken from the following controller:</p>
  
  <pre><code>public HttpResponseMessage ExportGridToExcelWithFilters ()
  {
      using (ExcelPackage pck = new ExcelPackage())
      {
          var excelData = ExcelExportVM.GenerateExcelFile(pck);
          using (MemoryStream ms = new MemoryStream())
          {
              excelData.SaveAs(ms);
              HttpResponseMessage responsePackage = new HttpResponseMessage();
              responsePackage.Content = new ByteArrayContent(ms.GetBuffer());
              responsePackage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
              return responsePackage;
          }
      }
  }
  </code></pre>
  
  <p>Changing the above code to produce less data:</p>
  
  <pre><code>for (int i = 0; i &lt; 10; i++) //FROM 1000
  {
      DataRow row = dt.NewRow();
      row["A"] = "Value";
      row["B"] = "Value";
      row["C"] = "Value";
      row["D"] = "Value";
      row["E"] = "Value";
      dt.Rows.Add(row);
  }  
  </code></pre>
  
  <p>It now works and I am able to open the file without entering recovery mode. </p>