Getting while we copy workbook from source to destination for specific Template. Intermittent issue

Hi Team,
Can you please help for below
Getting Exception for below code snippet.

Workbook copyWb = new Workbook();
Workbook wbOutput = new Workbook(“<>.xlsx”);
copyWb.copy(wbOutput);

Exception:
Cannot read the array length because “this.i” is null:[com.aspose.cells.g0g.o(Unknown Source), com.aspose.cells.n26.a(Unknown Source), com.aspose.cells.Cells.a(Unknown Source), com.aspose.cells.Worksheet.copy(Unknown Source), com.aspose.cells.WorksheetCollection.a(Unknown Source), com.aspose.cells.Workbook.copy(Unknown Source), com.aspose.cells.Workbook.copy(Unknown Source)

This issue occurring for specific workbook. But if we save the same workbook again and try to execute the same code on it. works well.
We open on workbook, after this we do lot of processing and imports of worksheets. This increases size of workbook to 20mb(in memory),

We know, you will require workbook to investigate the issue but would be difficult to provide since, its not always reproducible. Can you please help share the probable root causes related to exception, so that we can try to resolve those locally by making changes in workbook itself without code changes.

@forasposeissues

The exception you are encountering, “Cannot read the array length because ‘this.i’ is null,” typically indicates that there is an issue with the workbook you are trying to copy. This error can occur due to various reasons, especially when dealing with specific workbooks that may have corrupted data or unsupported features.

Here are some potential causes and suggestions to resolve the issue:

  1. Workbook Corruption: The workbook you are trying to copy might be corrupted. If saving the workbook again resolves the issue, it suggests that the original file may have inconsistencies. You can try to manually inspect the workbook for any unusual formatting, hidden sheets, or unsupported features.

  2. Memory Limitations: Since you mentioned that the workbook size increases significantly (up to 20MB), ensure that your environment has sufficient memory allocated. If the application runs out of memory, it may lead to unexpected behavior.

  3. Unsupported Features: Check if the workbook contains features that are not supported by Aspose.Cells, such as certain types of charts, complex formulas, or external links. You can simplify the workbook by removing or replacing these features.

  4. Version Compatibility: Ensure that you are using the latest version of Aspose.Cells. Sometimes, bugs are fixed in newer releases, and upgrading might resolve your issue.

  5. Debugging: If feasible, try to isolate the specific sheet or data causing the issue. You can do this by copying sheets one by one to identify which one triggers the exception.

  6. Using CopyOptions: When copying workbooks, consider using the CopyOptions class to specify how the copy operation should behave. This can help avoid issues related to formatting and references.

If you continue to experience issues, consider reaching out to Aspose support with specific details about the workbook and the operations you are performing. They may provide additional insights or solutions tailored to your situation.

For further reference, you can check the documentation on copying worksheets and workbooks to understand the methods and options available here and here.

Sources:
[1]: Copying and Moving Worksheets - Aspose Documentation
[2]: Workbook | Aspose.Cells for Java API Reference

@forasposeissues

Which version of Aspose.Cells are you using when getting this problem? Please provide us the version number so we may check whether we can get some more details from the exception. And please try our latest version to check whether the issue has been solved if you are not using it already.

Generally for such kind of issue there are two many possibilities of the cause and it is hard or impossible for us to trace it without the reproducable code and template file. Please try to check whether you can add some debug codes and processes to save the wbOutput to local file, and then you may provide us the one which can reproduce the issue when copying it to a new workbook so we can look into the issue further.