title: Error while generating excel from datatable in C#
body: <p>I am getting error when using <strong><a href="http://epplus.codeplex.com/" rel="nofollow">EPPlus</a></strong> library to generate excel from a datatable</p>
  
  <p><em>System.ObjectDisposedException: Package object was closed and disposed, so cannot carry out operations on this object or any stream opened on a part of this package.</em></p>
  
  <p>I searched and found <a href="http://epplus.codeplex.com/discussions/262170" rel="nofollow">here</a> that <code>GetAsByteArray()</code> function disposes of the package object.
  Please help to overcome this .</p>
  
  <pre><code>private void DumpExcel(DataTable tbl)
  {
      using (ExcelPackage pck = new ExcelPackage())
      {
  
          //Create the worksheet
          ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Demo");
  
          //Load the datatable into the sheet, starting from cell A1. 
          //Print the column names on row 
          ws.Cells["A1"].LoadFromDataTable(tbl, true);
  
  
          Response.Clear();
          Response.ClearContent();
          Response.ClearHeaders();
  
          Response.AddHeader("content-disposition", "attachment;  filename=ExcelDemo.xlsx");
          Response.AddHeader("content-type", "application/Excel");
          Response.ContentType = "application/vnd.xls";
          Response.AddHeader("content-length", pck.GetAsByteArray().Length.ToString());
          Response.BinaryWrite(pck.GetAsByteArray());
      }
  }
  </code></pre>
  
  <p><br>
  <strong>Please Note :</strong> I want to generate excel and leave it to user to save the excel report anywhere they want on local computer rather than specifying path on server in which excel gets saved.</p>