title: Generating Large Excel report from database using epplus
body: <p>I want to generate excel report using EPPlus library. Here is my code for loading file in initialization:</p>
  
  <pre><code>ExcelPackage pkg = new ExcelPackage(new FileInfo(filePath));
  </code></pre>
  
  <p>I face the <code>OutOfMemoryException</code> because of large data in my report.  An <a href="http://www.codeproject.com/Tips/659666/Export-very-large-data-to-Excel-file" rel="nofollow noreferrer">codeproject article</a> describes how to create large excel report. The author approach is to save report for portion of data into Excel file, close the package and then reopen the excel file and add another portion of data to it and so on... . I applied this to my project:</p>
  
  <pre><code>//Going to save log package.
  pkg.Save();
  //Package saved and Disposed.
  var fileInfo = pkg.File;
  
  //Again loading file into package...
  pkg.Load(new FileStream(fileInfo.FullName, FileMode.Open));
  </code></pre>
  
  <p>The point here is that when I Save package, it will be disposed automatically. After disposing <strong>I suppose that memory will be released, but when I see the task manager it does not happens.</strong> After that I again load excel file <a href="https://stackoverflow.com/questions/12912912/save-as-using-epplus#answer-13376386">as discribed in another post in stackoverflow</a>.</p>