This project has moved. For the latest updates, please go here.

Close package

Aug 20, 2012 at 12:13 PM

How do I close a package? I want to close the whole Excel spreadsheet that was opened by EPPlus.

Aug 20, 2012 at 10:41 PM

The ExcelPackage class implements IDisposable, so either you can declare your package inside a using-statement or you can call the Dispose() method explicitly when you are done. I would recommend using-statement since it will make sure Dispose is called even if an exception occurs.


Aug 22, 2012 at 7:06 AM

Yes, thanks for that - my mistake. I looked at my code ( I wrote a wrapper class to implement EPPlus) and realized that I used a shell command to show Excel. So it cannot be closed from EPPlus. Once Excel has opened the file, you must manually close it. The alternative is not to show it but to leave it up to the user to open and close.