A way to share picture data in a file

I’ve found if I add a image in file, and set the same image to CommentShape as fill texture, it will add 2 same image data in file.
In plan, we need add a large number of pictures into file in this way, which may lead to a large number of unnecessary duplication of picture resources to cause the file to become twice as large.

Is there any “resource sharing” optimization solution?

It will output a single xlsx file, won’t consider the solution about reference external image file.

@Flithor,

Aspose.Cells works the same way as MS Excel does. Do you think MS Excel does resource sharing in your desired way, please elaborate with sample Excel file containing such image(s)? We will look into it soon.

sheet.Pictures.Add(0, 0, new MemoryStream(imgData));
var comment = sheet.Comments[sheet.Comments.Add(0, 0)];
comment.CommentShape.Fill.ImageData = imgData;

Will include 2 same image.

Is this a file format limitation that prevents sharing?

I’ve tried in Excel, it’s save double image, too.

@Flithor
In your sample code, first you added a Picture, and then you created a Comment. Comment is also a shape, where you set the data of the image as the background of the comment, so you will have two images.

If add 2 same image will share the image resource.
But the image fill in CommentShape will not share.

Looks it’s the xlsx file limitation.

@Flithor,

It can be file format limitation. In case, you could get your desired results by performing the task manually in MS Excel, share the Excel file, we will check it further.

@Flithor
Excel divides all shapes into two categories:Drawing and VML drawing(comments, forms, activeX controls).Maybe different teams designed them and they used two picture data pool.
But I directly changed setting in the xlsx file to make CommentShape share same picture data with Image, MS Excel could open the changed xlsx file fine. So maybe MS Excel forgot them together.

I have log a ticket :CELLSNET-54290. We will look into whether we can share them.

@Flithor,

This is to inform you that your issue (logged as “CELLSNET-54290”) has been resolved. The fix will be included in our upcoming release version (Aspose.Cells v23.10) scheduled for release in first half of October 2023. We will let you know when the next release is published.

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