Aspose cells ignoring image in cell range

Hello all,

We are using a licensed version of Aspose.Cells and we have the following problem. I can generate an image (call it a snapshot) from the workbook that I want in all cases that I tried (with a cell range, with a chart, with a chart sheet, etc.) but one. The situation is that I have a cell range (lets say AQ20:AX34) and inside that cell range there is a picture that is generated from an absolute cell reference (AQ4:AX18), so when the image is generated from the workbook the “linked picture” (AQ4:AX18) is lost but all the formatting, coloring and data in the desired range (AQ20:AX34) is still there.

My code in a summary:

Worksheet sheet = workbook.Worksheets[sheetName];

 ImageOrPrintOptions imageOptions = new ImageOrPrintOptions();
 imageOptions.ImageType = Aspose.Cells.Drawing.ImageType.Jpeg;

var snapshotStream = new MemoryStream();
                          ...
sheet.PageSetup.PrintArea = $"{fromCell}:{toCell}";
                           ...

 imageOptions.OnePagePerSheet = true;

SheetRender render = new SheetRender(sheet, imageOptions);

render.ToImage(0, snapshotStream);

Do you have any idea why that is happening and how to “catch” the linked image?

Thank you in advance!

Stoil

@s.yankov16,

Thanks for the sample code and details.

Could you provide us your template file, we will check it soon.

PS. please zip the Excel file prior attaching.

Thank you for the fast reply.

Heres the attached template.

Example.zip (19.7 KB)

@s.yankov16,
We were able to observe the issue but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSNET-47264 – Worksheet Image in a cell range not rendered to image

@s.yankov16,

We tested it further and found the linked picture is rendered but I see an issue with e.g horizontal category axis labels and other minor things. Please try our latest version/fix: Aspose.Cells for .NET v20.3.3 (attached)
Aspose.Cells20.3.3 For .Net2_AuthenticodeSigned.Zip (5.3 MB)
Aspose.Cells20.3.3 For .Net4.0.Zip (5.3 MB)

If you still find the issue, kindly provide output image, exact code and a screenshot to highlight the issue, we will check it soon.

@s.yankov16,
We have checked and observed that this issue is reproduced in macOS whereas the image is rendered properly in Windows. Could you please share your environment details?

Thank you again for the quick update!

@ahsaniqbalsidiqui
The image is rendering just fine on my local Windows machine, but fails to render on the server that we deploy the project. It is running on a service plan on MS Azure (PremiumV2 if that helps).

Framework: .NET 4.7
Platform: 32 bit

Please do ask if you need more information.

@Amjad_Sahi

As for the patch, I added it as a reference to the project, but now I get the following error:

CS7069 Reference to type ‘ImageFormat’ claims it is defined in ‘System.Drawing’, but it could not be found

For line:
sheet.Charts[nameOfChart].ToImage(stream, imageOptions);

I tried adding System.Drawing and etc. but with it persists. Maybe I did something wrong while referencing it. Do you have any idea about that error?

EDIT: I removed the lines that throw an error to test it out, but the license now fails, because it is for versions until 18th of January. Does that mean we have to upgrade our license to get the patch?

@s.yankov16,

Thanks for providing us environment details and further information about the issue.

We will evaluate your issue and get back to you soon.

And, yes, to use latest version/fix, you need to upgrade your subscription. You may try to comment the licensing code (for the time being) to check how latest fix goes in your environment/server.

I have tried the patch and unfortunately it doesnt solve our problem.

Image of the result on deployed environment:
image.png (82.6 KB)

Code:

            var startstream = new MemoryStream(workbookByteArray);
            
            Workbook workbook = new Workbook(startstream);                

            Worksheet sheet = workbook.Worksheets[sheetName];

            ImageOrPrintOptions imageOptions = new ImageOrPrintOptions();

            imageOptions.ImageType = Aspose.Cells.Drawing.ImageType.Jpeg;
            imageOptions.OnlyArea = true;

            imageOptions.HorizontalResolution = 300;
            imageOptions.VerticalResolution = 300;
            imageOptions.OnePagePerSheet = true;

            var snapshotStream = new MemoryStream();
            

            var cellRange = cells.Split(':');
            var fromCell = cellRange[0];
            var toCell = cellRange[1];

           sheet.PageSetup.PrintArea = $"{fromCell}:{toCell}";

            SheetRender render = new SheetRender(sheet, imageOptions);

            render.ToImage(0, snapshotStream);

            resultStreams.Add(snapshotStream.ToArray());

Any other information that I can provide?

@s.yankov16,
Thank you for providing the feedback. We will consider it while working on this issue.

@s.yankov16,

We evaluated your issue further. It seems that you use an ASP.NET Framework web app in Azure (Quickstart: Deploy an ASP.NET web app - Azure App Service | Microsoft Learn). Could you please share a runnable project with us to analyze the issue.

Also, please try the following code on your Azure environment. The attached “image1.emf” in the zipped archive is exported from the your shared “Example.xlsx”:

using(Bitmap destImage = new Bitmap(600, 600))
{
    using (Graphics g = Graphics.FromImage(destImage))
    {
        g.Clear(Color.Blue);
        using (Image emfImage = Image.FromStream(emfStream))    //emfStream load for image1.emf
        {
            g.DrawImage(emfImage, 0, 0);
        }
    }

    MemoryStream pngStream = new MemoryStream();
    destImage.Save(pngStream, ImageFormat.Png);

    resultStreams.Add(pngStream.ToArray());
}

Please note and as we know, the emf image is limited (not supported) on Azure.
image.zip (5.3 KB)