Aspose.Cells version - 5.1.3.0
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)We are getting error in the Save method call.
{
if (LastSheetIdx > 0) targetWkObj.Worksheets.Add(SheetType.Worksheet);
targetWkObj.Worksheets[LastSheetIdx].Copy(wk);
targetWkObj.Worksheets[LastSheetIdx].Name = wk.Name;
LastSheetIdx++;
}
targetWkObj.Save(absoluteFilePath, SaveFormat.Xlsx);
Please advise on the code changes OR some workaround to prevent the error and successful generation of excel file.