System.InvalidOperationException: "A worksheet with this name already exists in the workbook"

Sep 1, 2014 at 7:22 AM
Edited Sep 1, 2014 at 11:45 AM

i really love this package. The performance is really amazing. But unfortunately i have a horrible problem. I'm using EPPlus to create around 10-30 xlsx-files each time in my program. After 8-10 iterations the export algorithm throws an exception, saying that the worksheet already exists in the workbook when im adding a new one. The wicked thing is, that this can't be, cause every time i export a file, the ExcelPackage should be disposed since i use the "using" statement.
This is how my export looks like:
using (ExcelPackage pck = new ExcelPackage(newFile))
   for (int i = 0; i < ListSheetNames.Count; i++)
       ExcelWorksheet Sheet = pck.Workbook.Worksheets.Add(ListSheetNames[i]);
       // Filling Sheet from DataTable
Even if i delete the sheets manually after saving the ExcelPackage the bug still exists:
while (pck.Workbook.Worksheets.Count > 0) { pck.Workbook.Worksheets.Delete(1); }
Anyone with an idea? The export-method is static, is that the reason maybe?
I tried to reproduce this problem with the sample projects, creating 20-30 times the same sample-project but the error won't occure. :(

The only workaround for now is to check the workbook for a existing sheet, delete it, and re add it. But thats pretty stupid, cause the workbook should be empty...