I receive the following error when opening a workbook: Index was outside of bounds of the array

Hi team.

I receive the following error when opening a workbook: Index was outside of bounds of the array. Therefore, I cannot open this Excel file. I am using Aspose.Cells for .net version 4.5.0.0. That’s the license purchased by my client. I have this simple code to open the workbook from my Excel file, which includes 2 sheets:

public int UpdateAssetDataWithTemplateFile(string TemplateFileName, int userId)
{
{
if (File.Exists(TemplateFileName))
{
Workbook wb = new Workbook();
try
{
wb.Open(TemplateFileName);
}
catch (Exception ex)
{
LogBO log = new LogBO(this.GetType());
log.Error(ex.Message + "\r\n - " + ex.StackTrace);
return -1;
}

        Worksheet ws = null;

        if (wb.Worksheets == null || wb.Worksheets.Count < 1)
            return 0;

        int result = 0;

//code goes here for the worksheets…
return result;
}

Here is the StackTrace:

System.IndexOutOfRangeException

HResult=0x80131508

Message=Index was outside the bounds of the array.

Source=Aspose.Cells

StackTrace:

at Aspose.Cells.OpenXML.x7661ca2b53df3da9.xbd93b3b4862f01e7(XmlTextReader xb9763b0038341e6c)

at Aspose.Cells.OpenXML.x7661ca2b53df3da9.x06b0e25aa6ad68a9(XmlTextReader xb9763b0038341e6c)

at Aspose.Cells.OpenXML.x9d49ab444acbddce.x72bde2882aefe5af(x1f5f0dd7560ed867 xd9171314ec0b2957, String x7d11dcd405070662)

at Aspose.Cells.OpenXML.x9d49ab444acbddce.xc3266f78bb6c4216(x1f5f0dd7560ed867 xd9171314ec0b2957, String x7d11dcd405070662)

at Aspose.Cells.OpenXML.x9d49ab444acbddce.x88ae89d546ee9fdf()

at Aspose.Cells.OpenXML.xe95a61e48a6637a3.x2e7f798eabefe5b4(Workbook xce16031e3118b903, Stream xcf18e5243f8d5fd3)

at Aspose.Cells.Workbook.Open(String fileName)

at GISAP.AssetFramework.BO.Asset.AssetBOV2.UpdateAssetDataWithTemplateFile(String TemplateFileName, Int32 userId) in C:\Users\panayota.panayotou\source\repos\IPG-CorpIT-Global\IPGITHK_Asset_and_Benchmark_Backend\Source\AssetFramework_API\GISAP.AssetFramework\BO\Asset\AssetBOV2.cs:line 22

This exception was originally thrown at this call stack:

[External Code]

GISAP.AssetFramework.BO.Asset.AssetBOV2.UpdateAssetDataWithTemplateFile(string, int) in AssetBOV2.cs

I attach the Excel file I am using to open. I can’t find what’s causing this error. I am thinking that the file is maybe corrupted. This file has been created from another function we have in the application we are using. I can also attach the code for this file creation.
AssetListReport_AL505_373.zip (8.6 KB)

@PanLog,

Thank you for providing the XLSX template file.

I have tested your scenario using our latest version/fix: Aspose.Cells for .NET v24.6 and it works perfectly. Below is the sample line of code that I am using, which works fine without any exceptions.
e.g.,
Sample code:

Workbook wb = new Workbook("e:\\test2\\AssetListReport_AL505_373.xlsx");

We are sorry, but we cannot evaluate your issue using an older version of the API. Neither can we fix issues in older versions. I suspect that the issue is due to your use of an older version of the API (4.5.0.0), which may have limitations or bugs when reading/writing XLSX file formats. The reason may be that at that time, the API might not have been efficient in parsing or rendering XLSX or advanced Excel file formats. We strongly recommend that you kindly upgrade to the latest versions of the API set, as over the years we have included many enhancements and supported many new/useful features to make the component more robust and feature-rich.

See the docs for your reference.
https://docs.aspose.com/cells/net/

Moreover, see the featured demos/examples for your reference.
https://github.com/aspose-cells/Aspose.Cells-for-.NET

The exported Excel file has been saved with FileFormatType excelFileFormat = FileFormatType.Excel2007Xlsx; Afterwards, if someone tries to open that file with the function wb.Open(TemplateFileName) he/she gets the error message: “Index was outside the bounds of the array”. Is there any workaround to solve that issue with the version that our client has? (That is Aspose.Cells version 4.5.0.0)

@PanLog,

We are sorry, but since you are using an older version of the API that was published some years ago, we cannot evaluate your issue or help you much. As we mentioned before, we cannot include fixes for older versions, as the fixes are based on the latest API set only. Apparently, there is no workaround except upgrading to newer versions to cope with it. Anyways, we will still check if there is any other way around so you can remove or update something in the file manually, but the chances are slim.