Re: Chart distortion on embedded Excel OLE

  •  01-18-2010, 2:45 AM

    Re: Chart distortion on embedded Excel OLE

    Attachment: Present (inaccessible)

    Hi,

    I am not sure if this approach is going to work for you or not, but I wanted to share this information that you can also add the Excel chart as an image over slide object. Please have a look over the code snippet shared below in which first the chart in "simplechart.xls" file is accessed into Bitmap object and then I have simply placed it inside the shapes collection of slide using AddPictureFrame (...) method.

    C# .NET

    Workbook  wb = new Workbook();
    //Obatianing the filestream of the excel file containing the chart/charts in it
    FileStream fstro = new FileStream("c:\\simplechart.xls", FileMode.Open, FileAccess.Read);
    //Laoading the file stream of referenced excel file in workbook
    wb.Open(fstro);

    //Loading the chart in Bitmap. We've chart at worksheet3
    Bitmap imgChart = wb.Worksheets[2].Charts[0].ToImage();
    // create a presentation object
    Presentation pres = new Presentation();
    Slide slide = pres.GetSlideByPosition(1);
    // Adding the Bitmap in the picture frame
    Aspose.Slides.Picture pic = new Aspose.Slides.Picture(pres, imgChart);
    //Adding the picture object to pictures collection of the presentation
    //After the picture object is added, the picture is given a uniqe picture Id
    int picId = pres.Pictures.Add(pic);
    //Calculating picture width and height
    int pictureWidth = pres.Pictures[picId - 1].Image.Width * 4;
    int pictureHeight = pres.Pictures[picId - 1].Image.Height * 4;
    //Calculating slide width and height
    int slideWidth = slide.Background.Width;
    int slideHeight = slide.Background.Height;
    //Calculating the width and height of picture frame
    int pictureFrameWidth = Convert.ToInt32(slideWidth / 2 - pictureWidth / 2);
    int pictureFrameHeight = Convert.ToInt32(slideHeight / 2 - pictureHeight / 2);

    //Adding picture frame to the slide
    slide.Shapes.AddPictureFrame(picId, pictureFrameWidth, pictureFrameHeight,
    pictureWidth, pictureHeight);
    //Saving the ppt file
    pres.Write("c:\\ImageSlide.ppt");


    Mudassir Fayyaz
    Support Developer
    Aspose Sialkot Team
    Contact Us
    Aspose - The .NET and Java Component Publisher

    Keep in touch! We're on Twitter and Facebook
View Complete Thread