Failure to open .xlsm error: System.IndexOutOfRangeException

Here is the code I am running:

namespace Aspose.Cells
public class Workbook : IDisposable
{
public Workbook(string file)
}
new Aspose.Cells.Workbook("attached excel file”)

When I run this code against the attached excel file I get the: System.IndexOutOfRangeException : Index was outside the bounds of the array.
Constraint_Cost_Allocation_Report.zip (10.8 KB)

@mjkruzel3

Cause

The System.IndexOutOfRangeException typically occurs when trying to access an element in an array or collection using an index that is outside its valid range. In your case, this error may be occurring due to issues with the structure of the .xlsm file you are trying to open, such as corrupted data or unsupported features.

Solution

To troubleshoot this issue, consider the following steps:

  1. Check File Integrity: Ensure that the .xlsm file is not corrupted. Open it in Excel to verify that it opens without errors.

  2. Use LoadOptions: When opening files, especially with macros, specify load options. This can help manage how the file is read and may prevent issues related to unsupported features.

  3. Update Aspose.Cells: Ensure that you are using the latest version of Aspose.Cells, as updates often include bug fixes and improvements for handling various file formats.

Code

Here’s an example of how to use LoadOptions when opening your .xlsm file:

using Aspose.Cells;

public void OpenWorkbook(string filePath)
{
    // Create LoadOptions for the workbook
    LoadOptions loadOptions = new LoadOptions(LoadFormat.Xlsm);
    
    // Load the workbook with specified load options
    Workbook workbook = new Workbook(filePath, loadOptions);
    
    // Proceed with your logic
}

Next Steps

  1. Verify the integrity of the .xlsm file by opening it in Excel.
  2. Implement the above code with LoadOptions to see if it resolves the issue.
  3. If the problem persists, share the file with Aspose support for further analysis.

Please follow these steps, and let me know if you need any further assistance!

@mjkruzel3,

Thanks for the template XLSM file.

After initial testing, I am able to reproduce the issue as you mentioned by reading your template XLSM file into Aspose.Cells object model. I found ‘System.IndexOutOfRangeException’ occurred in Aspose.Cells.dll: ‘Index was outside the bounds of the array.’" on loading the file.

Workbook workbook = new Workbook("e:\\test2\\Constraint_Cost_Allocation_Report.xlsm");

We require thorough evaluation of the issue. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSNET-58681

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@mjkruzel3,

We are pleased to inform you that your issue (Ticket ID: “CELLSNET-58681”) has been resolved. The fix/enhancement will be included in the upcoming release (Aspose.Cells v25.7) that we plan to release in the first half of July 2025. You will be notified when the next version is published.

The issues you have found earlier (filed as CELLSNET-58681) have been fixed in this update. This message was posted using Bugs notification tool by leoluo