Search code examples
excelconsole-application.net-6.0syncfusion

Syncfusion XlsIO: Trying to insert list of images from folder into each row. Same image showing


I am using Syncfusion XlsIO in a .NET 6 Console Application to insert data into a sheet including an image on the end of each row. I am following the official documentation here.

There are no errors but when I open the file file after the application completes I see the same image being inserted into every row. I have stepped through the loop and I can see the image object changing. Below is the code I am using:

int row = 1;
foreach (DataRow dataRow in imgTable.Rows)
{
    Console.WriteLine(dataRow.ToString());
    string imagePath = $"./tempImages/{dataRow.ItemArray[1]}";

    using (FileStream imageStream = new FileStream(imagePath, FileMode.Open, FileAccess.Read))
    {
        IPictureShape shape = alarmWorksheet.Pictures.AddPicture(row, 4, imageStream);
        imgWorksheet.SetRowHeight(row, 288);
    }

    row++;
}

I have also tried this because there is an overload for the Image type.

int row = 1;
foreach (DataRow dataRow in imgTable.Rows)
{
    alarmWorksheet.SetRowHeight(row, 216);
    Console.WriteLine(dataRow.ToString());
    string imagePath = $"./tempImages/{dataRow.ItemArray[1]}";

    using (FileStream imageStream = new FileStream(imagePath, FileMode.Open, FileAccess.Read))
    {
        Image img = new Image(imageStream);
        imgWorksheet.Pictures.AddPicture(row, 4, img);
    }

    row++;
}

Solution

  • TL;DR: This was a bug since version 20.0.4.54 that got resolved in version 23.1.40.


    Original answer including chronological updates:

    I had the same issue while upgrading some old code.

    I seems like you need to keep Syncfusion.XlsIO.Net.Core at or below version 20.0.4.54 seems to work. I realize this is not a permanent solution but perhaps you can live with it for now.

    I've reported this as a bug to Syncfusion, perhaps you can do the same.

    [Update 1] I just got a reply from Syncfusion support that they are looking at my report and will update shortly. I figured I will update this answer with the progress.

    [Update 2] Syncfusion said they "have fixed a similar issue in our recent version of XlsIO. We request you upgrade to the latest NuGet version 23.1.40 and check whether the issue is resolved." I don't have time to test that now, but I'll do that shortly.

    [Update 3] Final update: The latest version fixes the issue for me, also see the official answer by Syncfusion.