【问题标题】:aspose excel GetCellIndex index out of bounds for empty cellsaspose excel GetCellIndex索引超出空单元格的范围
【发布时间】:2015-11-30 13:37:18
【问题描述】:

我正在使用 Aspose Cells 从 excel 文件中获取数据 在每一行我都有这样的数据

| Name | PhoneNumber | Email | Group

| Jack | +1456985    |    | Users

当我尝试用这个从行中读取联系人时

((Row)currentContact).GetCellByIndex(2).StringValue

代码给了我应该返回“”的“用户” 然后

((Row)currentContact).GetCellByIndex(3).StringValue

实际上应该返回 "Users" 但是这一行抛出 IndexOutOfBoundException 。

似乎 aspose 跳过了空单元格。 谁能帮我解决这个问题?

【问题讨论】:

    标签: c# aspose-cells


    【解决方案1】:

    首先,请注意,最近发布的 Aspose.Cells API 已经淘汰了 Row.GetCellByIndex 方法,因此它很快就会从公共 API 中删除。替代解决方案是 Row.GetEnumerator 方法。关于您最初的担忧, Row.GetCellByIndex 和 Row.GetEnumerator 方法都不会列出尚未初始化的单元格。换句话说,如果指定的单元格甚至包含一个空字符串,它将被正确读取,否则将被跳过。您可以使用 Row.GetCellOrNull 方法来测试单元格是否已初始化。如果您有更多问题,请随时在此处或Aspose.Cells support forum 与我们联系。

    我与 Aspose 合作,担任开发人员宣传员。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-06
      • 1970-01-01
      相关资源
      最近更新 更多