Some shapes within an Excel picture replaced with a default image when that picture is inserted into Word

We’re selecting an image in an Excel spreadsheet and the Aspose picture for this image is then getting encoded in Base64 and saved to the database.
We then have Word documents, created programmatically, which are to use this image. To do this, the Aspose picture is retrieved from the database and decoded. It is then inserted into the document via DocumentBuilder.

Issue
We’ve noticed an issue where sometimes certain shapes within the image are missing, or at least don’t get converted correctly. One such example is the 2D arrow shapes.
When the image is viewed in the word document, these shapes are replaced with a no-entry sign.
The image itself was a screen grab from another excel spreadsheet which contained the shapes. The excel spreadsheet containing the image has been attached. The Workbook which was passed to the code below was created from the uploaded Excel spreadsheet.UAH.zip (1.3 MB)
UAH.zip (1.3 MB)

Does Aspose have an issue converting some of these shapes from an image to an Aspose picture, or could you please advise if there is a better approach for us to use?

image.png (863 Bytes)
image.png (10.9 KB)

Product Used
Aspose.Words 21.8.0
Aspose.Cells 21.10.0

Code Used

  1. When saving content to DB from Excel:

//Workbook is firstly loaded from MemoryStream from the physical file then passed in to this method
private void FindMatchingContent(Workbook workbook, string excelLink)
{
var pictures = new List();
string imageContentForDB = string.Empty;

foreach (var sheet in workbook.Worksheets)
{
    var worksheetCharts = sheet.Pictures;
    pictures.AddRange(worksheetCharts);
}

var matchingPicture = pictures.FirstOrDefault(picture => $"{picture.Worksheet.Name}_{picture.Name}" == excelLink);
if (matchingPicture != null)
{
imageContentForDB = ConvertToBase64EncodedString(matchingPicture);
//Save to DB
}
}

public static string ConvertToBase64EncodedString(Picture picture)
{
using var stream = new MemoryStream();
picture.ToImage(stream, GetImageExportOptions());
var imageContent = Convert.ToBase64String(stream.ToArray());
var content = string.Concat(EncodedImagePrefix, imageContent);
return content;
}

private static ImageOrPrintOptions GetImageExportOptions()
{
const int resolution = 300;
return new ImageOrPrintOptions
{
OnePagePerSheet = true,
ImageType = ImageType.Png,
SmoothingMode = SmoothingMode.AntiAlias,
HorizontalResolution = resolution,
VerticalResolution = resolution
};
}

  1. When loading content into Word document:

private static void SetContent(DocumentBuilder documentBuilder, string content, Paragraph paragraph)
{
documentBuilder.MoveTo(paragraph);
var pageInfo = PageSizeLayoutHelper.GetPageInfo(documentBuilder);
var bytes = Convert.FromBase64String(
content.Replace(“data:image/png;base64,”, string.Empty));
var shape = documentBuilder.InsertImage(bytes);

//code to resize image if necessary

}

@frlspr

Thanks for the template file and screenshots.

I did test your scenario/case a bit. I used the following simplest code to render each picture in the “Export Images” worksheet (in your template XLSM file) to PNG image. The output images are fine tuned, I do not spot your mentioned issue in the output images by Aspose.Cells for .NET APIs.
e.g.
Sample code:

            Workbook workbook = new Workbook("e:\\test2\\UAH.xlsm");

            Worksheet sheet = workbook.Worksheets["Export Images"];
            const int resolution = 300;
            ImageOrPrintOptions options = new ImageOrPrintOptions();
            options.OnePagePerSheet = true;
            options.ImageType = ImageType.Png;
            options.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            options.HorizontalResolution = resolution;
            options.VerticalResolution = resolution;
            int i = 0;
            foreach (var picture in sheet.Pictures)
            {
                picture.ToImage("e:\\test2\\outpic_" + (++i) +".png", options);
     
            }

Please find attached the zipped archive containing the output images.
files1.zip (1.2 MB)

I am using our latest version of Aspose.Cells for .NET v22.3, please try it. I guess the issue may not be with Aspose.Cells APIs. The issue might be when encoded the image to save to database or when retrieving the image to decode it to be inserted into MS Word document. Anyways, if you still think it is an issue with Aspose.Cells APIs, kindly do create a standalone sample project (source code without compile time errors) with latest version of Aspose.Cells for .NET APIs, zip the project and provide us to reproduce the issue on our end, we will check it soon. The sample project should not have inter-dependencies with database or external source and can be executed seamlessly. We will check it soon.

Thanks for your help and suggestions. For anyone else encountering something similar, we’ve now found that this was actually a font issue.
In our application, when the image is selected in Excel, the Aspose Picture would get encoded to the Database. A service running on our server would then locate the encoded Aspose Picture from the database and attempt to convert this to an image, but the arrows in the picture are from the Wingdings 3 font.
This font was installed on the client machines (with Office), but was not installed on our server - and therefore not rendered correctly.

@frlspr,

Thanks for sharing your findings.

Good to know that your issue is sorted out now. Feel free to write us back if you have further queries or issue, we will be happy to assist you soon.