Unable to scale the size and change the position of an OleObjectFrame

Just wanted to check If I am trying to activate the OLE Objects in the PPTX such that I don’t see “Embedded OLe Object”.
what C# code I need to write and I did not wanted to use any third party tool other than aspose.
neither I want user to maually go and click on each Ole Object to activate it.
Any existing code /sample solution would be really helpful.
Please help
I need this on urgent basis for my project.Please guide

@souravsinghblr,

As I shared with you earlier that there is no mechanism to automatically activate the OLE Object using Aspose.Slides since it is handled by OLE Engine. Third party macros that are VB codes may be used in this regard to activate the OLE objects when presentation is Opened in PowerPoint. Aspose.Slides only offers a workaround solution to replace the red “Embedded OLE” image with any image of your choice when you add OLE frame. That image can be an image of Worksheet that you may get using Aspose.Cells or any other thing. The following code may be a helpful reference for your convenience to see how to set image for OLE Object.

    public static void TestExcel()
    {
        Aspose.Cells.License lic = new Aspose.Cells.License();
        lic.SetLicense("C:\\Aspose Data\\Aspose.Total.lic");

        String path = @"C:\Aspose Data\";

        //Step - 1: Create an excel chart using Aspose.Cells
        //--------------------------------------------------
        //Create a workbook
        //    string filePath = GetTemplateFolderPath() + "F9_Test_RAV.xlsx";
       
        string filePath = path + "SampleExcel.xlsx";
        Workbook wb = new Workbook(filePath);
        //Step - 2: Set the OLE size of the chart. using Aspose.Cells
        //-----------------------------------------------------------
       
        
        wb.Worksheets.SetOleSize(0, 14, 0, 8);
        //Step - 3: Get the image of the chart with Aspose.Cells
        //-----------------------------------------------------------
        Bitmap imgChart = wb.Worksheets[0].Charts[0].ToImage();
        //Save the workbook to stream
        MemoryStream wbStream = wb.SaveToStream();
        //Step - 4  AND 5
        //-----------------------------------------------------------
        //Step - 4: Embed the chart as an OLE object inside .ppt presentation using Aspose.Slides
        //-----------------------------------------------------------
        //Step - 5: Replace the object changed image with the image obtained in step 3 to cater Object Changed Issue
        //-----------------------------------------------------------
        //Create a presentation
        Presentation pres = new Presentation();
        ISlide sld = pres.Slides[0];
        //Add the workbook on slide
        float oleWidth = 5.070f * 72f;
        float oleHeight = 2.670f * 72f;
        int x = 0;
        byte[] chartOleData = new byte[wbStream.Length];
        wbStream.Position = 0;
        wbStream.Read(chartOleData, 0, chartOleData.Length);
        IOleObjectFrame oof = null;
        oof = sld.Shapes.AddOleObjectFrame(x, 0, oleWidth, oleHeight, "Excel.Sheet.12", chartOleData);
        oof.SubstitutePictureFormat.Picture.Image = pres.Images.AddImage(imgChart);
        //Step - 6: Write the output presentation on disk
        //-----------------------------------------------------------
        pres.Save(path + "OutputChart2.pptx", Aspose.Slides.Export.SaveFormat.Pptx);

    }

@mudassir.fayyaz Thanks a lot it worked I am able to get the Excel Image instead of “Embedded Ole Object”.

Few more areas in which I had issues:

  1. I wanted to display the table instead of this icon from the first time.I am want to render the table just like we might have copy pasted. I don’t want the user to double click and then see the table.
    2.I do not want show all the rows in the excel table I just want to display the top 10 and I want those 10 rows to occupy full height and width.
    3.When we click on the excel it should not overflow it should have scroll on both side to navigate to different parts of excel data.

I am using both Aspose.cells and I am geeting stream from here and utilizing in the Aspose.Slides,

Please help.
I will need sample code implementation for it.It will be really helpful.

Thanks & Regards,
Sourav.

@souravsinghblr,

For your following query:

There is following property in IOleObjectFrame interface that when set to false will not display Ole frame as icon.

IOleObjectFrame.IsObjectIcon

I have not been able to understand the above question. Can you please share elaboration for this.

@souravsinghblr,

For your following query

Please use following code to render specific cells range to image and share the feedback.

// Create workbook from source file.
Workbook workbook = new Workbook(path + "Book1.xlsx");

// Access the first worksheet
Worksheet worksheet = workbook.Worksheets[0];

// Set the print area with your desired range
worksheet.PageSetup.PrintArea = "D8:G16";

// Set all margins as 0
worksheet.PageSetup.LeftMargin = 0;
worksheet.PageSetup.RightMargin = 0;
worksheet.PageSetup.TopMargin = 0;
worksheet.PageSetup.BottomMargin = 0;

// Set OnePagePerSheet option as true
ImageOrPrintOptions options = new ImageOrPrintOptions();
options.OnePagePerSheet = true;
options.ImageFormat = ImageFormat.Jpeg;
options.HorizontalResolution = 200;
options.VerticalResolution = 200;

// Take the image of your worksheet
SheetRender sr = new SheetRender(worksheet, options);
sr.ToImage(0, path + "outputExportRangeOfCellsInWorksheetToImage.jpg");

You may visit following article for more details about rendering spread sheets to image.
Workbook Conversions

Still I don’t get the excel table directly,we get an image on which you have to double click then an excel table opens. Is their an way to directly render table not the icon/image?(Working Solution)

One more thing when we click on the Embedded Ole Object/Icon, excel is opened but it’s size in inappropriate to edit.It should not exceed the slide size in apose.slide.
I am attaching an image of issue I am facing.
Please help.issue.JPG (43.3 KB)

Thanks a lot for the reply.
I wanted to show the raw excel table itself not image when it loads first time. Such that it will be directly editable.
Is their any way to achieve it?If we can render the excel directly/ Not the image or icon in a particular dimension within the slide it would be great. Table should not exceed the dimension of the slide in apose.slide while editing.
It becomes so big while editing(attaching the image of issueissue.JPG (43.3 KB)
)

@souravsinghblr,

I suggest you to please try using following sample code on your end to avoid resizing. The resizing occurs because of Aspose.Cells and Aspose.Slides have different pixels/inch values.

public static void TestExcel()
{
      
    String path = @"C:\Aspose Data\";

    //--------------------------------------------------
       
    string filePath = path + "SampleData.xlsx";
    Workbook wb = new Workbook(filePath);
    //Step - 2: Set the OLE size of the chart. using Aspose.Cells
    //-----------------------------------------------------------
        
    wb.Worksheets.SetOleSize(0, 20, 0, 20);
    //Step - 3: Get the image of the chart with Aspose.Cells
    //-----------------------------------------------------------

    Worksheet dataSheet = wb.Worksheets[0];
    String sheetName = "DataSheet";
    dataSheet.Name=sheetName;
    //Set chart print area
    dataSheet.PageSetup.PrintArea=dataSheet.Cells[0,0].Name + ":" +
            dataSheet.Cells[20, 20].Name;

    // Get the chart worksheet as image
    ImageOrPrintOptions imageOptions = new ImageOrPrintOptions();
    imageOptions.ImageFormat=ImageFormat.Emf;
    imageOptions.OnlyArea=true;
    imageOptions.OnePagePerSheet=true;
    SheetRender sheetRender = new SheetRender(wb.Worksheets[0], imageOptions);
      
    //            ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
    //           sheetRender.toImage(0, imageStream);
    MemoryStream imageStream = new MemoryStream();
    // Bitmap imgChart = sheetRender.ToImage(0, imageStream);
    sheetRender.ToImage(0, imageStream);
    imageStream.Position = 0;
    byte[] imageByteArray = imageStream.ToArray();

    MemoryStream wbStream = new System.IO.MemoryStream();// wb.SaveToStream();

    wb.Save(wbStream, Aspose.Cells.SaveFormat.Xlsx);
        
    //Create a presentation
    Presentation pres = new Presentation();
    ISlide sld = pres.Slides[0];
    //Add the workbook on slide
    float oleWidth = 5.070f * 72f;
    float oleHeight = 2.670f * 72f;
    int x = 0;
    byte[] chartOleData = new byte[wbStream.Length];
    wbStream.Position = 0;
    wbStream.Read(chartOleData, 0, chartOleData.Length);
    IOleObjectFrame oof = null;
    oof = sld.Shapes.AddOleObjectFrame(x, 0, pres.SlideSize.Size.Width, pres.SlideSize.Size.Height, "Excel.Sheet.12", chartOleData);
    //oof = sld.Shapes.AddOleObjectFrame(x, 0, oleWidth, oleHeight, "Excel.Sheet.12", chartOleData);
    oof.SubstitutePictureFormat.Picture.Image = pres.Images.AddImage(imageByteArray);
    //Step - 6: Write the output presentation on disk
    //-----------------------------------------------------------
    pres.Save(path + "OutputChart2.pptx", Aspose.Slides.Export.SaveFormat.Pptx);

}

Thanks a lot it worked for me.
One issue I am facing is that It works perfectly in Office 2013.
But in 2016 it doesn’t work. I am facing the resizing issue.
It’s urgently needed for us.
Please help.

Even When I am rendering an excel Image I am facing this issue.
For office 2013 It works fine. But for 2016 when I click on ole icon it’s size changes.
Please help, it’s urgently required.

@souravsinghblr,

I have observed the issue statement shared by you and request you to please share the working sample project along with source presentation and generated output. Please also provide the the snapshots for issue when viewed in PowerPoint 2013 and PowerPoint 2016 for comparison as well.

I am attaching the Image for 2016 in which after I clicked on OleObject Snapshot Image and closed it …table goes beyond slide(In 2016).

But if I do the same in 2013 it is not going beyond the slide(Attached the Image).

I was earlier getting same issue for 2013 but I used you above mentioned code which resolve the issue but same is not working for 2016.
I am attaching the code
Please help.<a class=“attachment” href="/uploaDesktop.zip (137.4 KB)
ds/discourse_instance3/17934">ImageFor2013.jpeg (87.4 KB)
ImageFor2016.jpeg (80.7 KB)

Same issue for OleEmbedded ICon as well

@souravsinghblr,

Thank you for sharing the information. However, I am unable to find the source presentation, source Excel file used in sample code along with generated output presentation as well. Please share the requested information so that we may log issue in our issue tracking system.

I am attaching the PPTX and XLSX File. However these are sample files.
But issues are same.PPTX.zip (51.3 KB)
It will really helpful if you can guide me on this.

@souravsinghblr,

Thank you for sharing the information. I have created an issue with ID SLIDESJAVA-37315 in our issue tracking system to further investigate the issue on our end. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

I am using .net c#.

@souravsinghblr,

Thank you for sharing the information. I have created an issue with ID SLIDESNET-40493 in our issue tracking system to further investigate the issue on our end. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

I need this urgently. Any workaround or solution for this will be really helpful.

@souravsinghblr,

I have observed your comments. I like to inform that we will investigate this issue in details and share feedback with you regarding workaround or ETA. I request for your patience.