1

I'm using LoadXls to upload a file from a stream and I get the following error:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at External.CompoundFile.ReadData.(BinaryReader , ArrayList& )
   at External.CompoundFile.ReadData..ctor(Ole2CompoundFile , Stream )
   at External.CompoundFile.Ole2CompoundFile.Load(Stream , Boolean )
   at GemBox.Spreadsheet.XlsLoadOptions.(Stream , Boolean , Byte[]& , Byte[]& , Boolean , Byte[]& , Byte[]& , Ole2Storage&  )
   at GemBox.Spreadsheet.XlsLoadOptions.(ExcelFile , Stream )
   at GemBox.Spreadsheet.LoadOptions.(ExcelFile , Stream , String )
   at GemBox.Spreadsheet.LoadOptions.(ExcelFile , Stream , String , Boolean )
   at GemBox.Spreadsheet.ExcelFile.LoadXls(Stream stream)

I'm using GemBox.SpreadSheet.dll version 41.3.30.1047 (free license).

What could be wrong with the stream? It's a MemoryStream I create by obtaining the stream directly from a cloud storage service (AWS S3, Bluemix, Google Cloud Storage, Azure).

Here is the xls I'm trying to load

Solution: The solution ended up being setting the MemoryStream's position to beginning before reading it.

4

1 回答 1

0

马里奥 Z的建议解决了这个问题。

在读取之前尝试将 MemoryStream 的位置设置为开始,例如使用“memoryStream.Seek(0, SeekOrigin.Begin);” 或使用“memoryStream.Position = 0;”

于 2021-09-15T13:19:41.030 回答