This repository was archived by the owner on Mar 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
This repository was archived by the owner on Mar 9, 2020. It is now read-only.
CompoundDocumentFile throws System.ArgumentOutOfRangeException: Index was out of range. #131
Copy link
Copy link
Open
Description
Encountered on 2d08514
The following scenario will generate ArgumentOutOfRangeException
exception
FileInfo TempFile(string name)
{
var baseFolder = Path.Combine(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()));
Directory.CreateDirectory(baseFolder);
return new FileInfo(Path.Combine(baseFolder, name));
}
[TestMethod]
public void MustNotThrowWhenWhenHaving65Sheets()
{
var src = TempFile("report.xlsm");
var package = new ExcelPackage(src);
var sheets = Enumerable.Range(1, 65)
.Select(x => $"Sheet{x}");
foreach (var sheet in sheets)
package.Workbook.Worksheets.Add(sheet);
package.Workbook.CreateVBAProject();
package.Workbook.VbaProject.Modules.AddModule("Module1").Code
= "\r\nPublic Sub SayHello()\r\nMsgBox(\"Hello\")\r\nEnd Sub\r\n";
package.Save();
}
Here is the full exception
Test method EPPlusTest.VBA.MustNotThrowWhenWhenHaving65Sheets threw exception:
System.InvalidOperationException: Error saving file C:\Users\gengle\AppData\Local\Temp\jkbrtwwt.ikk\report.xlsm ---> System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.ThrowHelper.ThrowArgumentOutOfRange_IndexException()
at System.Collections.Generic.List`1.get_Item(Int32 index)
at OfficeOpenXml.Utils.CompundDocument.CompoundDocumentFile.SetSiblings(List`1 l, List`1 children, Int32 pos, Int32 div) in C:\Users\gengle\source\EPPlus\EPPlus\Utils\CompundDocument\CompoundDocumentFile.cs:line 486
at OfficeOpenXml.Utils.CompundDocument.CompoundDocumentFile.SetSiblings(List`1 l, List`1 children, Int32 pos, Int32 div) in C:\Users\gengle\source\EPPlus\EPPlus\Utils\CompundDocument\CompoundDocumentFile.cs:line 494
at OfficeOpenXml.Utils.CompundDocument.CompoundDocumentFile.SetSiblings(List`1 l, List`1 children, Int32 pos, Int32 div) in C:\Users\gengle\source\EPPlus\EPPlus\Utils\CompundDocument\CompoundDocumentFile.cs:line 494
at OfficeOpenXml.Utils.CompundDocument.CompoundDocumentFile.SetSiblings(List`1 l, List`1 children, Int32 pos, Int32 div) in C:\Users\gengle\source\EPPlus\EPPlus\Utils\CompundDocument\CompoundDocumentFile.cs:line 494
at OfficeOpenXml.Utils.CompundDocument.CompoundDocumentFile.SetSiblings(List`1 l, List`1 children, Int32 pos, Int32 div) in C:\Users\gengle\source\EPPlus\EPPlus\Utils\CompundDocument\CompoundDocumentFile.cs:line 494
at OfficeOpenXml.Utils.CompundDocument.CompoundDocumentFile.AddChildren(CompoundDocumentItem item, List`1 l) in C:\Users\gengle\source\EPPlus\EPPlus\Utils\CompundDocument\CompoundDocumentFile.cs:line 464
at OfficeOpenXml.Utils.CompundDocument.CompoundDocumentFile.AddChildren(CompoundDocumentItem item, List`1 l) in C:\Users\gengle\source\EPPlus\EPPlus\Utils\CompundDocument\CompoundDocumentFile.cs:line 469
at OfficeOpenXml.Utils.CompundDocument.CompoundDocumentFile.FlattenDirs() in C:\Users\gengle\source\EPPlus\EPPlus\Utils\CompundDocument\CompoundDocumentFile.cs:line 440
at OfficeOpenXml.Utils.CompundDocument.CompoundDocumentFile.Write(MemoryStream ms) in C:\Users\gengle\source\EPPlus\EPPlus\Utils\CompundDocument\CompoundDocumentFile.cs:line 425
at OfficeOpenXml.Utils.CompundDocument.CompoundDocument.Save(MemoryStream ms) in C:\Users\gengle\source\EPPlus\EPPlus\Utils\CompundDocument\CompoundDocument.cs:line 120
at OfficeOpenXml.VBA.ExcelVbaProject.Save() in C:\Users\gengle\source\EPPlus\EPPlus\VBA\ExcelVBAProject.cs:line 602
at OfficeOpenXml.ExcelWorkbook.Save() in C:\Users\gengle\source\EPPlus\EPPlus\ExcelWorkbook.cs:line 838
at OfficeOpenXml.ExcelPackage.Save() in C:\Users\gengle\source\EPPlus\EPPlus\ExcelPackage.cs:line 831
--- End of inner exception stack trace ---
at OfficeOpenXml.ExcelPackage.Save() in C:\Users\gengle\source\EPPlus\EPPlus\ExcelPackage.cs:line 899
at EPPlusTest.VBA.MustNotThrowWhenWhenHaving65Sheets() in C:\Users\gengle\source\EPPlus\EPPlusTest\VBA.cs:line 95
What's known
- Error appears to be related to number of worksheets -- 65 and 100 fail
- Appears to be how the BTree index is handled with the mcdf implimentation
- Current CompoundFile Implementation is light on testing and I have overall concerns on it's implementation. Should we consider using an alternative, such as https://github.com/CodeCavePro/OpenMCDF
Metadata
Metadata
Assignees
Labels
No labels