2

I'm trying to save a file using EPPlus, but I keep getting an InvalidOperationException on the Save() line.

System.IO.File.Copy(strSource, strNewNotePath, true);
ExcelPackage xlPackage = new ExcelPackage(new FileInfo(strNewNotePath));
xlPackage.Save();

The InnerException says "Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index".

The Excel file has very little in it - just a few drawing items really - rounded rectangles, textboxes, and then two cells with some data in them.

Anyone got any ideas what could be causing this?

Thanks

Jez Clark
  • 383
  • 5
  • 19
  • This turned out to be a broken Excel file. I pasted the contents of the old file into a brand new workbook, used the same code on it and it ran with no errors. No idea exactly what caused it, other than that the previous file was a sheet exported from an old .xls (not xlsx) file, so maybe that was the culprit... – Jez Clark Nov 22 '12 at 17:42
  • Assuming the xls file was created using an excel version prior to 2007, that would make sense since it would not have been using OpenXml. – Chris Sep 20 '14 at 14:55

1 Answers1

0

I was having the same problem in version 3.0.0.2 of EPPlus. I tried created new excel files, re-saving existing ones but that didn't work. I got the lastest version (as of 20141016 (3.1.3.0)) and it worked fine.