We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Importing image from excel has broken aspect ratio

Hello, we are taking images from excel and adding them to ppt slides. It works well except when the text in excel cells is wider than the width of printed area.

I attached resulted slide (redacted) for reference as well as original excel file. As you can see the two images come from sheets of the same size however one is much wider giving it a different aspect ratio (the aspect ratio is the real issue for me). It is triggered by having a lot of text in the overflowing cell.

Desktop.zip (202.9 KB)

Funny that writing files to disk or using Image.FromStream(stream) give matching ratios but lower quality and higher ppt size.

The generated image itself has correct scaling but when added to a slide it ends up with, for example, width:150% while height is ok at 100%.

Furthermore if I save to disk and read it back again the glitch disappears. It seems some strange scaling info is carried in the memory stream when calling p.Images.AddImage(stream)

Below is the code I used to generate this:

public void demo()
            new Aspose.Cells.License().SetLicense(@"....Aspose.Cells.lic");
            new Aspose.Slides.License().SetLicense(@"....\Aspose.Slides.lic");

            Workbook wb = new Workbook(@"....ExcelWithChart.xlsx");
            Presentation p = new Presentation(@"....PPTTemplate.pptx");
            ISlide template = p.Slides[0];

            fillSlide(wb, p, template, 0);
            fillSlide(wb, p, template, 1);

            p.Save(new FileStream(@"....output.pptx", FileMode.Create), Aspose.Slides.Export.SaveFormat.Pptx);

        private static void fillSlide(Workbook wb, Presentation p, ISlide template, int index)
            var slide = p.Slides.InsertClone(0, template);

            MemoryStream stream = getStream(wb, index);
            IPPImage image = p.Images.AddImage(stream);

            IPictureFrame toBeReplace = slide.Shapes.FirstOrDefault(x => x.Name == "tableImage") as IPictureFrame;
            int indexOfImage = slide.Shapes.IndexOf(toBeReplace);
            IPictureFrame pictureFrame = slide.Shapes.InsertPictureFrame(indexOfImage, toBeReplace.ShapeType,
                toBeReplace.X, toBeReplace.Y, image.Width, image.Height, image);

            pictureFrame.Name = toBeReplace.Name;

        private static MemoryStream getStream(Workbook wb, int index)
            var sheet = wb.Worksheets[index];
            PageSetup pageSetup = sheet.PageSetup;
            pageSetup.PrintArea = "A1:F5";
            pageSetup.RightMargin = pageSetup.BottomMargin = pageSetup.LeftMargin = pageSetup.TopMargin = 0;
            var stream = new MemoryStream();
            new Aspose.Cells.Rendering.SheetRender(sheet, IMAGE_OR_PRINT_OPTIONS).ToImage(0, stream);
            stream.Position = 0;
            return stream;

    public static Aspose.Cells.Rendering.ImageOrPrintOptions IMAGE_OR_PRINT_OPTIONS
            return new Aspose.Cells.Rendering.ImageOrPrintOptions
                SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality,
                EmfType = System.Drawing.Imaging.EmfType.EmfPlusDual,
                ImageType = Aspose.Cells.Drawing.ImageType.Emf,
                PrintingPage = Aspose.Cells.PrintingPageType.IgnoreBlank,
                IsCellAutoFit = true,
                OnePagePerSheet = true,


I have observed the issue shared by you and tested using Aspose.Slides for .NET 19.11 and Aspose.Cells for .NET 19.11. Even saving generated EMF on disk and then adding that Picture frame has issues on my end. I have created an issue with ID SLIDESNET-41621 in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

The issues you have found earlier (filed as SLIDESNET-41621) have been fixed in this update.