Error saving the file

Hello, 

I am using the XlsIO library(24.1400.41.0) to create an Excel file:

   Excel Engine excel Engine = new Excel Engine();

   Application application = excel Engine.Excel;

   application.Default Version = Excel Version.Excel 2010;

   Workbook workbook = application.Workbooks.Create(1);

I also add photos to the cells in the comment field:

   Image _image = Image.FromStream(stream);

   double kf = 1;

   if (_max Pic Height < _image.Height) kf = (double)_image.Height / _maskheight;

   worksheet.Range["F" + _A.ToString()].AddComment().Height = (int)(_image.Height / kf);

   worksheet.Range["F" + _A.ToString()].AddComment().Width = (int)(_image.Width / kf);

   worksheet.Range["F" + _A.ToString()].Add Comment().Fill.UserPicture(_image, "Image.jpg");


All this happens without errors.

But when I try to save a file:

   workbook.SaveAs(@"C:\Users\admin\Desktop\ms_res.xslx");


I get an error:

The index is out of range. The index must be a positive number, and its size must not exceed the size of the collection.Parameter name: index


This error does not occur with all lines, but I cannot understand why it appears.


How do I understand exactly what the error is and in what kind of situation it occurs?


Attachment: stack_trace_7780f11b.zip

3 Replies

KM Kurmitha Manickhaperumal Syncfusion Team January 25, 2024 11:27 AM UTC

Hi,

 

We have confirmed the issue and logged a defect report. We will include the fix for this issue in our upcoming weekly NuGet release scheduled for February 06, 2024.

 

The status of the bug can be tracked through the below feedback link

Feedback link:  Exception is thrown while saving the Excel document containing comments with picture fill | Feedback Portal

 

Regards,

Kurmitha M.



HI Hole io Online June 18, 2025 09:46 AM UTC

You should only add comments once, and then use variables to manipulate them. This ensures that you don't accidentally create multiple comment objects hole io on the same cell, which can easily lead to "index out of range" errors.



AR Aravazhi Rajendran Syncfusion Team June 24, 2025 06:01 AM UTC

Hi Hole io Online,

Thank you for your suggestion but this issue is associated with picture fill.

Regards,
Aravazhi Rajendran


Loader.
Up arrow icon