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.

moondaisy
  • 4,303
  • 6
  • 41
  • 70
  • Can you upload your XLS file somewhere so that I can take a look at it? If not then you should submit a support ticket (with that XLS file attached) on GemBox Software Support Center. – Mario Z Feb 11 '17 at 12:46
  • @MarioZ I've updated my question to include the file. – moondaisy Feb 13 '17 at 12:12
  • I was unable to reproduce the issue, I loaded that file into a MemoryStream and used "ExcelFile.Load(MemoryStream, LoadOptions.XlsDefault)" without any issue. This will require investigating the way how the stream is handled in your application, can you submit a VS test project that reproduces your issue [here](http://support.gemboxsoftware.com/new-ticket). – Mario Z Feb 13 '17 at 12:43
  • @MarioZ If I create the MemoryStream from a local file it works, but i'm getting the stream from a cloud storage provider (I have edited the question to include the ones I've tried) and with all of them I get the same error. I use this same stream with EPPlus, using the ExcelPackage constructor, without any problems – moondaisy Feb 14 '17 at 13:59
  • 1
    again unfortunately without investigating and reproducing this I cannot help you, so you should consider submitting a support ticket (as I mentioned above). For now, all I can do is guess and my guess is to try setting the MemoryStream's position to beginning before reading it, for example with "memoryStream.Seek(0, SeekOrigin.Begin);" or with "memoryStream.Position = 0;". If that does not help then again consider submitting a support ticket, otherwise I'm afraid no one will be able to help you with this. – Mario Z Feb 14 '17 at 15:30
  • you mentioned that you tried with EPPlus? I'm not sure how you did that, EPPlus library does not support XLS, it only supports XLSX file format? Can you explain how did you load an XLS file into it? – Mario Z Feb 14 '17 at 15:34
  • @MarioZ I will try setting the position. And I used the stream from an xlsx file in EPPLus, but it was obtained in the same way the one I want to use here from a cloud storage provider. – moondaisy Feb 14 '17 at 17:29

1 Answers1

0

Mario Z suggestion resolved the issue.

try setting the MemoryStream's position to beginning before reading it, for example with "memoryStream.Seek(0, SeekOrigin.Begin);" or with "memoryStream.Position = 0;"

IHAFURR
  • 111
  • 4