Dynamic images don't refresh properly

Support,

Using the technique in video below, you can create a dynamic picture frame by referencing a cell (directly or through a Index/Match formula). The attached Excel file shows this example. Change cell G2 in the attached file to “Image 2” to see the working example.

The challenge we’re having is it doesn’t seem that Aspose updates the picture object when the formulas are calculated. We notice this because our task is to calculate the formulas and then save a copy of the image from the picture box using the code below. When we do this we see that the picture box doesn’t update.

DynamicLogo.zip (50.4 KB)

Picture picture = worksheet.Pictures.FirstOrDefault(x => x.Name == address);
 var options = new ImageOrPrintOptions()
 {
     ImageType = ImageType.Png,
     Transparent = true
 };
picture.ToImage(stream, options);

Thank You
-Andy

@weissa,

Thanks for the sample file demo video.

After an initial test, I am able to reproduce the issue as you mentioned by using your template Excel file and following sample code. I found dynamic images don’t refresh properly in the output PDF/image file.

Workbook workbook = new Workbook("e:\\test2\\DynamicLogo.xlsx");

Worksheet worksheet = workbook.Worksheets["Images"];
workbook.Save("e:\\test2\\out1.pdf");//Ok

worksheet.Cells["G2"].PutValue("Image 2");
workbook.CalculateFormula();
workbook.Worksheets.SortNames();

workbook.Save("e:\\test2\\out1.xlsx");//Ok
workbook.Save("e:\\test2\\out1.pdf");//Not Ok

We require thorough evaluation and investigation of the issue. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSNET-55840

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@weissa ,

Please call worksheet.Shapes.UpdateSelectedValue(); after changing cell G2 to update picture.
Code:

var options = new ImageOrPrintOptions()
{
    ImageType = ImageType.Png,
    Transparent = true
};

Workbook workbook = new Workbook("DynamicLogo.xlsx");

Worksheet worksheet = workbook.Worksheets["Images"];
worksheet.Pictures[2].ToImage("before_updating.png", options);

worksheet.Cells["G2"].PutValue("Image 2");
worksheet.Shapes.UpdateSelectedValue();
worksheet.Pictures[2].ToImage("after_updating.png", options);

This doesn’t seem to work. I’m using Aspose 24.1.0 and before saving images of the pictures I call this code:

workbook.Worksheets.ToList().ForEach(x=> x.Shapes.UpdateSelectedValue());

The stale image seems to remain. Would a CalculateFormula or something else also be needed?

Thank You,
-Andy

@weissa
before_updating.zip (11.2 KB)

Please check the attached images with 24.1. It looks fine.

@simon.zhao,

I updated to v25 and still having the issue. I would like to do some more testing in case I’m making a mistake. I’ll get back to this soon.

Thanks,
-Andy

@weissa,

Yes, please make sure you are using 24.x to test your scenario/case. We tested using recent versions with suggested code segment after adding line of code: ‘worksheet.Shapes.UpdateSelectedValue();’ and it works fine. You may print the Aspose.Cells version in code so you should judge which version is being used for your case.

Console.WriteLine("Version: " + CellsHelper.GetVersion());

@amjad.sahi ,

I was having inconsistent results with your example and have finally figured out why. It turns out that if you Delete a worksheet before performing the Cell update and Shapes.UpdatedSelectedValue, then the shapes do not update properly.

Using the attached workbook and the example below. Commenting the Worksheets.RemoveAt will show the correct behavior, uncommenting the line will show the incorrect behavior. The DeleteMe worksheet is blank and has no involvement in the images or formulas.

   [Test]
    public void foo46()
    {
        var filename = @"C:\Data\Systems\Demo\Reports\Support\DynamicLogo.xlsx";
        var imagePath = @"C:\Data\Temp\out.png";
        var workbook = new Workbook(filename);

        Worksheet worksheet = workbook.Worksheets["Images"];

        workbook.Worksheets.RemoveAt("DeleteMe"); // Comment this line to make work
        worksheet.Cells["G2"].PutValue("Image 2");
        workbook.CalculateFormula();

        worksheet.Shapes.UpdateSelectedValue();

        worksheet.Pictures.First(x => x.Name == "DynamicLogo").ToImage(imagePath, new ImageOrPrintOptions()
        {
            ImageType = ImageType.Png,
            Transparent = true
        });
    }

DynamicLogo.zip (47.6 KB)

Thank You,
-Andy

@weissa,

Thank you for providing the sample file and the information.

Upon conducting an initial test, I was able to replicate the issue you mentioned using your template Excel file. It appears that dynamic images do not refresh properly when a worksheet is removed before performing the cell update and Shapes.UpdatedSelectedValue.

We require thorough evaluation of the issue. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSNET-55981

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@amjad.sahi,

I was just checking to see if this issue was addressed in any of the recent Apose releases or if it’s still a pending issue.

Thank You,
-Andy

@weissa,

The issue (logged earlier as “CELLSNET-55981”) has not been resolved yet. Hopefully, we will schedule it soon. Once we have an update on it, we will let you know here.

We are sorry for any inconvenience caused.

1 Like

@weissa

This is to inform you that your issue (Ticket ID: “CELLSNET-55981”) has been resolved. The fix will be included in an upcoming release (Aspose.Cells v24.9) that we plan to release in the first half of September 2024. You will be notified when the next version is released.

The issues you have found earlier (filed as CELLSNET-55981) have been fixed in this update. This message was posted using Bugs notification tool by johnson.shi