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

Free Support Forum - aspose.com

Cells to image affected by cell content

I am 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 if 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 (60.5 KB)

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

Below is the code I used to generate this:

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

            Workbook wb = new Workbook(@"...ExcelWithChart.xlsx");
            Presentation p = new Presentation(@"...Template.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);

            slide.Shapes.Remove(toBeReplace);
            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
        {
            get
            {
                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,
                };
            }
        }

@Mihai_Bratulescu,
We are working on this issue but could not find the template.pptx file in Desktop.zip used in the sample code. Could you please share the template.pptx file for our testing?

Sorry I missed it. PPTTemplate.zip (88.0 KB)

Also to note again: 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)

.

I have tried my own code to verify it but could not succeed. Please share the code which can be used to verify the above mentioned behaviour. Also share the output file generated after this change.

@Mihai_Bratulescu,
We suggest you to create a thread in Aspose.Slides forum first to see what causes the issue. Then some changes/fixes can be made in Aspose.Slides or Aspose.Cells.