We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose.Cells -Worksheet Copy action results in error on Save method call

Aspose.Cells version -

Error received on saving the workbook :-
Must be non-negative and less than the size of the collection. Parameter name: index

Integration code:-

Workbook targetWkObj = new Workbook();
Workbook sourceWkObj = new Workbook(templateFile);
int LastSheetIdx = 0;

foreach (Worksheet wk in sourceWkObj.Worksheets)
if (LastSheetIdx > 0) targetWkObj.Worksheets.Add(SheetType.Worksheet);
targetWkObj.Worksheets[LastSheetIdx].Name = wk.Name;

targetWkObj.Save(absoluteFilePath, SaveFormat.Xlsx);

We are getting error in the Save method call.

Please advise on the code changes OR some workaround to prevent the error and successful generation of excel file.


Well, as you are using some older version of the product for which I am not sure about it. We recommend you to kindly try our latest version/fix: Aspose.Cells for .NET v8.1.1.1 if it makes any difference.

If you still find the issue with latest version v8.1.1.x, kindly do share your template Excel file here, we will check your issue soon.

Thank you.