【问题标题】:Gembox LoadXls IndexOutOfRangeExceptionGembox LoadXls IndexOutOfRangeException
【发布时间】:2017-06-29 02:57:16
【问题描述】:

我正在使用 LoadXls 从流中上传文件,但出现以下错误:

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)

我正在使用 GemBox.SpreadSheet.dll 版本 41.3.30.1047(免费许可)。

流可能有什么问题?这是我通过直接从云存储服务(AWS S3、Bluemix、Google Cloud Storage、Azure)获取流创建的 MemoryStream。

Here 是我要加载的 xls

解决方案: 最终解决方案是在读取之前将 MemoryStream 的位置设置为开始。

【问题讨论】:

  • 你能把你的 XLS 文件上传到某个地方让我看一下吗?如果没有,那么您应该在 GemBox 软件支持中心提交支持票(附上该 XLS 文件)。
  • @MarioZ 我已经更新了我的问题以包含该文件。
  • 我无法重现该问题,我将该文件加载到 MemoryStream 中并使用“ExcelFile.Load(MemoryStream, LoadOptions.XlsDefault)”没有任何问题。这将需要调查在您的应用程序中如何处理流的方式,您能否提交一个重现您的问题的 VS 测试项目here
  • @MarioZ 如果我从本地文件创建 MemoryStream 它可以工作,但我从云存储提供商获取流(我已编辑问题以包含我尝试过的问题)和对于所有这些,我都会遇到同样的错误。我在 EPPlus 中使用了这个相同的流,使用 ExcelPackage 构造函数,没有任何问题
  • 再次遗憾的是,如果没有调查和复制此问题,我无法帮助您,因此您应该考虑提交支持票(如上所述)。现在,我所能做的就是猜测,我的猜测是在读取之前尝试将 MemoryStream 的位置设置为开始,例如使用“memoryStream.Seek(0, SeekOrigin.Begin);”或使用“memoryStream.Position = 0;”。如果这没有帮助,请再次考虑提交支持票,否则恐怕没有人可以帮助您。

标签: c# xls indexoutofrangeexception gembox-spreadsheet


【解决方案1】:

Mario Z 的建议解决了这个问题。

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

【讨论】:

    猜你喜欢
    • 2012-06-11
    • 2012-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多