Embedding excel tables created from Aspose.cells as MemoryStream to Aspose.Slides

Hi,

I wanted to embedded an excel table which is created from Aspose.Cells and comes to me in Stream format in C#.
It should be visible/preview on the slide. It should not display “Embedded Ole Object” It should preview the data in slide.
The demo app/Code provide by Aspose opens the excel file with big fonts and it’s not visible/editable.
I tried importing one of the excel(8 kb) in Slide, but it shows “Not Enough Memory To Open The Worksheet.”
I am uploading the sample pptx that I am expecting.(Excel Should be have Preview and Editable)
Please help.
Capture.JPG (89.6 KB)

When I Open the PPTX next time.Excel gets displayed with huge area and It looks its impossible to fit it inside slide.

Thanks,
Sourav.

@souravsinghblr,

I have observed the issues shared by you. For your following question:

This is neither an issue with Aspose.Slides nor with PowerPoint. This is default behavior of PowerPoint that when you add Excel file using OLE Object in PowerPoint slide using Aspose.Slides the MSO OLE Engine adds red, “Embedded OLE” message image to OLE frame to show that OLE frame is disabled by default and you need to double click that in order to enable that and show preview of the OLE data it self. There are two possible workarounds for this. First that you can use any third party macros that can enable the OLE frames automatically when presentation is loaded in PowerPoint. The other option is to get the thumbnail of Excel sheet using Aspose.Cells and set that as OLE frame image to avoid Red message.

Again, Aspose.Slides does not limit to add Excel file as big as 8KB as OLE frame. Its a limitation on end of OLE Engine if it throws error on loading presentation with OLE frame. But still, I suggest you to please share a working sample project along with all source files and generated output that I may test on my end to help you further.

Thanks for the reply.
I was trying to set OLE frame image as Red Message.Not able to do it.
Do you have a working project for this?
I was trying to load after double clicking the OLE but execl opens up in huge size.
I tried using link Working Solution for Worksheet Resizing|Aspose.Slides Documentation.
But unable to execute it.Getting a Out Of Memory Exception.Any working solution project for this?
I have already a license for Aspose.

This is my sample code
using Aspose.Cells;
using Aspose.Cells.Rendering;
using Aspose.Slides;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
class Scaling
{
static void Main(string[] args)
{
WorkbookDesigner workbookDesigner = new WorkbookDesigner();
workbookDesigner.Workbook = new Workbook(@“C:\Users\singhs102\Desktop\PPTX\AsposeTest.xls”);

        Presentation presentation = new Presentation(@"C:\Users\singhs102\Desktop\PPTX\AsposeTest.ppt");

        ISlide slide = presentation.Slides[0];


        AddOleFrame(slide, 0, 15, 0, 3, 0, 300, 1100, 0, 0, presentation, workbookDesigner, true, 0, 0);

        String fileName = @"C:\Users\singhs102\Desktop\PPTX\AsposeTest_Ole.ppt";
        presentation.Save(fileName, Aspose.Slides.Export.SaveFormat.Ppt);
    }

/Methods used******/

private static void SetOleAccordingToCustomHeighWidth(Workbook workbook, Int32 startRow,
Int32 endRow, Int32 startCol, Int32 endCol, double slideWidth, double slideHeight, Int32 dataSheetIdx)
{
Worksheet work = workbook.Worksheets[dataSheetIdx];

        double actualHeight = 0, actualWidth = 0;

        double newHeight = slideHeight;
        double newWidth = slideWidth;
        double tem = 0;
        double newTem = 0;

        for (int i = startRow; i <= endRow; i++)
            actualHeight += work.Cells.GetRowHeightInch(i);

        for (int i = startCol; i <= endCol; i++)
            actualWidth += work.Cells.GetColumnWidthInch(i);
        ///Setting new Row and Column Height

        for (int i = startRow; i <= endRow; i++)
        {
            tem = work.Cells.GetRowHeightInch(i);
            newTem = (tem / actualHeight) * newHeight;
            work.Cells.SetRowHeightInch(i, newTem);
        }

        for (int i = startCol; i <= endCol; i++)
        {
            tem = work.Cells.GetColumnWidthInch(i);
            newTem = (tem / actualWidth) * newWidth;
            work.Cells.SetColumnWidthInch(i, newTem);

        }

    }


    private static void AddOleFrame(ISlide slide, Int32 startRow, Int32 endRow, Int32 startCol, Int32 endCol,
        Int32 dataSheetIdx, Int32 x, Int32 y, Double OleWidth, Double OleHeight,
        Presentation presentation, WorkbookDesigner workbookDesigner,
        Boolean onePagePerSheet, Int32 outputWidth, Int32 outputHeight)
    {
        String tempFileName = @"C:\Users\singhs102\Desktop\PPTX\icon";
        if (startRow == 0)
        {
            startRow++;
            endRow++;
        }

        //Setting active sheet index of workbook
        workbookDesigner.Workbook.Worksheets.ActiveSheetIndex = dataSheetIdx;

        //Getting Workbook and selected worksheet  
        Workbook workbook = workbookDesigner.Workbook;
        Worksheet work = workbook.Worksheets[dataSheetIdx];

        //Scaling rows height and coluumns width according to custom Ole size
        double height = OleHeight / 576f;
        double width = OleWidth / 576f;

        SetOleAccordingToCustomHeighWidth(workbook, startRow, endRow, startCol, endCol, width, height, dataSheetIdx);

        //Set Ole Size in Workbook
        workbook.Worksheets.SetOleSize(startRow, endRow, startCol, endCol);

        workbook.Worksheets[0].IsGridlinesVisible = false;

        //Setting Image Options to take the worksheet Image
        ImageOrPrintOptions imageOrPrintOptions = new ImageOrPrintOptions();
        imageOrPrintOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Bmp;
        imageOrPrintOptions.OnePagePerSheet = onePagePerSheet;

        SheetRender render = new SheetRender(workbookDesigner.Workbook.Worksheets[dataSheetIdx], imageOrPrintOptions);
        String ext = ".bmp";
        //render.ToImage(0, tempFileName + ext);
        //Image image = ScaleImage(Image.FromFile(tempFileName + ext), outputWidth, outputHeight);
        //String newTempFileName = tempFileName+"1" + ext;
        //image.Save(newTempFileName, ImageFormat.Bmp);
        render.ToImage(0, tempFileName);
        Image image = ScaleImage(Image.FromFile(tempFileName + ext), outputWidth, outputHeight);
        String newTempFileName = tempFileName + "1" + ext;
        image.Save(newTempFileName, ImageFormat.Bmp);

        //render.ToImage(0, @"C:\Users\singhs102\Desktop\PPTX\download.jpg");
        //Image img = Image.FromFile(@"C:\Users\singhs102\Desktop\PPTX\download.bmp");

        //Adding Image to slide picture collection
        //Picture pic = new Picture(presentation, newTempFileName);
        //int picId = presentation.Pictures.Add(pic);
        IPPImage pic = presentation.Images.AddImage(image);


        //Saving worbook to stream and copying in byte array
        Stream mstream = workbook.SaveToStream();
        byte[] chartOleData = new byte[mstream.Length];
        mstream.Position = 0;
        mstream.Read(chartOleData, 0, chartOleData.Length);

        //Adding Ole Object frame
        IOleObjectFrame oleObjectFrame = slide.Shapes.AddOleObjectFrame(x, y, Convert.ToInt32(OleWidth),
      Convert.ToInt32(OleHeight), "Excel.Sheet.8", chartOleData);

        //Setting ole frame Imnae and Alternative Text property    
        oleObjectFrame.FillFormat.PictureFillFormat.Picture.Image = pic;
        oleObjectFrame.AlternativeText = "image" + "Alt";
        //image.Dispose();
    }


    private static Image ScaleImage(Image image, Int32 outputWidth, Int32 outputHeight)
    {
        if (outputWidth == 0 && outputHeight == 0)
        {
            outputWidth = image.Width;
            outputHeight = image.Height;
        }
        Bitmap outputImage = new Bitmap(outputWidth, outputHeight, image.PixelFormat);
        outputImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);
        Graphics graphics = Graphics.FromImage(outputImage);
        graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
        System.Drawing.Rectangle srcDestRect = new System.Drawing.Rectangle(0, 0, outputWidth, outputHeight);
        graphics.DrawImage(image, srcDestRect, srcDestRect, GraphicsUnit.Pixel);
        graphics.Dispose();

        return outputImage;
    }
}

}

@souravsinghblr,

I have observed your comments. Can you please share source files along with generated result so that we may further investigate to help you out. Also please share which Aspose.Slides version you are using on your end.