Free Support Forum - aspose.com

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

Hi,

We have been using Aspose Slides for .Net 3.5 client profile 6.9.0 dll inorder to create an OleObjectFrame in a Presentation(ppt)

Since some issues related to us have been fixed in release Aspose Slides for .Net 3.5 client profile 7.5.0 dll, we are using this latest dll(7.5.0).

However, we are unable to scale the size and position of OleObjectFrame with the below code which was working fine for the previous dll version 6.9.0

Sample Code:

//Main code - Start

Presentation pres = new Presentation();

Slide sld = pres.AddEmptySlide();

Presentation m_masterTemplate = new Presentation(@"C:\\AnswersWeb66\\ANSWERSWEB\\SOURCE\\AnswersWeb6.6\\Test\\Portal\\PPTTemplates\Master.ppt");

Bitmap imgchart = new System.Drawing.Bitmap(@"C:/temp/Image.jpg");

MemoryStream wbStream = new MemoryStream();

addOLEObjectFrame(wbStream, imgchart, pres, sld, 295, 1007, 4814, 2678);

//Cloning the master slide

Slide clonedSlide = m_masterTemplate.CloneSlide(m_masterTemplate.GetSlideByPosition(1),

pres.Slides.LastSlidePosition + 1, pres, new System.Collections.SortedList());

// Now m_show contains 1 extra slide (cloned) + 1 logo master from m_masterTemplate.

// Replace master for m_show own slides and then

// delete the slide (not master) which was cloned from m_masterTemplate.

Slide logoMaster = pres.GetSlideById(clonedSlide.MasterId);

foreach (Slide slide in pres.Slides)

slide.ChangeMaster(logoMaster);

pres.Slides.Remove(clonedSlide);

pres.DeleteUnusedMasters();

pres.Write(@"C:/temp/Output.ppt");

//Main code - End

//Method used within the main code

public void addOLEObjectFrame(MemoryStream wbStream, Bitmap imgChart, Presentation pres, Slide sld, int SlideLeft, int SlideTop, int SlideWidth, int SlideHeight)

{

Aspose.Slides.Picture pic = new Aspose.Slides.Picture(pres, imgChart);

int picId = pres.Pictures.Add(pic);

byte[] chartOleData = new byte[wbStream.Length];

wbStream.Position = 0;

wbStream.Read(chartOleData, 0, chartOleData.Length);

OleObjectFrame oof = sld.Shapes.AddOleObjectFrame(SlideLeft, SlideTop, SlideWidth, SlideHeight, "Excel.Sheet.8", chartOleData);

oof.PictureId = picId;

}

I have attached the required input files and the output obtained for Aspose Slides .Net version 6.9.0 dll and Aspose Slides .Net version 7.5.0dll

Please look into this issue with high priority and let us know if any workaround is present to scale and change the position of the OleObjectFrame.

Kindly let me know if you need any further details.

Thanks,

Koundinya

Hi Koundinya,


I have worked with the sample code shared by you and suggest you to please perform slide cloning first and then add Ole frame to avoid resizing issue. Please use the following sample code as reference to serve the purpose. Please share, if I may help you further in this regard. I have also created an issue with ID SLIDESNET-34393 to investigate further that why the ole is getting resized if I change the master slide after I have added the Ole frame. Please use the following sample code to serve the purpose.


public static void OleTesting()
{

String path = @“D:\Aspose Data”;
Presentation pres = new Presentation();

Slide sld = pres.AddEmptySlide();

Presentation m_masterTemplate = new Presentation(path+“Master.ppt”);


//Cloning the master slide

Slide clonedSlide = m_masterTemplate.CloneSlide(m_masterTemplate.GetSlideByPosition(1), pres.Slides.LastSlidePosition + 1, pres, new System.Collections.SortedList());

// Now m_show contains 1 extra slide (cloned) + 1 logo master from m_masterTemplate.

// Replace master for m_show own slides and then

// delete the slide (not master) which was cloned from m_masterTemplate.

Slide logoMaster = pres.GetSlideById(clonedSlide.MasterId);

foreach (Slide slide in pres.Slides)

slide.ChangeMaster(logoMaster);

pres.Slides.Remove(clonedSlide);

pres.DeleteUnusedMasters();

Bitmap imgchart = new System.Drawing.Bitmap(path + “Image.jpg”);

MemoryStream wbStream = new MemoryStream();

addOLEObjectFrame(wbStream, imgchart, pres, sld, 295, 1007, 4814, 2678);


pres.Write(path + “OutputOle.ppt”);

//Main code - End

//Method used within the main code
}
public static void addOLEObjectFrame(MemoryStream wbStream, Bitmap imgChart, Presentation pres, Slide sld, int SlideLeft, int SlideTop, int SlideWidth, int SlideHeight)

{

Aspose.Slides.Picture pic = new Aspose.Slides.Picture(pres, imgChart);

int picId = pres.Pictures.Add(pic);

byte[] chartOleData = new byte[wbStream.Length];

wbStream.Position = 0;

wbStream.Read(chartOleData, 0, chartOleData.Length);

OleObjectFrame oof = sld.Shapes.AddOleObjectFrame(SlideLeft, SlideTop, SlideWidth, SlideHeight, “Excel.Sheet.8”, chartOleData);

oof.PictureId = picId;

}


Many Thanks,

Hi Mudassir,

When clicked inside an OleObjectFrame. It's size is getting shrinked.

I belive you come across this issue. We are facing the same issue too.

Can you let us know if any workaround is present to avoid this issue.

Let me know if you are not aware of this issue, so that i can share you much inputs.

Thanks,

Koundinya

Hi Koundinya,


I like to share that I have written an article in online documentation that serves the solution for Ole frame getting resized. issue. Please visit this documentation link for your convenience. I have also attached a sample project as well for your convenience in attached documentation link.

Many Thanks,

Hi Mudassir,

Unfortunately we could not use the workaround provided.

Can this issue be handled. If a fix was in progress.When is it going to release.

Thanks,

Koundinya P

Hi Koundinya,


Can you please share that with the workaround you meant the code snippet shared over this thread post. If yes, then I like to share that the only difference between workaround provided and your sample code is cloning order. In your case you are adding Ole frame first and then cloning slide. However, in my sample code, I have proposed you to apply master first and then add Ole frame. The approach shared by me worked well. I have also added an issue with ID SLIDESNET-34393 to investigate that why Ole frame get resized when master is applied on it. This issue is pending for investigation at the moment and I will share the information with you as soon as it will be shared by our development team.

Many Thanks,

Hi Mudassir,

The code i shared with you is only for the Scaling issue with OleObjectFrame.The workaround you proposed has worked for PPT. We were able to Scale the size and position of the OleObjectFrame.

On clicking on the OleObjectFrame, the change in size is less and can be accepted.However, what is the behaviour when PPTX is considered. When we click on the OleObjectFrameEx it is shrinking its size more compared to the shrinking of PPT OleObjectFrame.

Is investigation going on this too.

Thanks,

Koundinya P

Hi Koundinya P,


I have observed the issue statement shared by you and it seems you are having issue with OleObjectFrameEx in PPTX now. Earlier, you shared the issue with PPT. For chart resizing in case of PPTX, please visit this documentation link. If there is still an issue then please share the sample application along with source presentation, generated presentation and expected output. I am hopeful that above shared link will be helpful to you in resolving the issue.

Many Thanks,

Hi,

I tried using this solution in your link for resizing issue.
https://docs.aspose.com/display/slidesnet/Working+Solution+for+Worksheet+Resizing
But I am getting an runtime exception in c# (Out Of Memory Exception).
bacuse of Image image = ScaleImage(Image.FromFile(tempFileName + ext), outputWidth, outputHeight);
Because of this Line Image.FromFile(tempFileName + ext);
Do you some working .Net Solution project for this?
Please help

Thanks,
Sourav.

@souravsinghblr,

I have observed your comments. Can you please share source files so that we may further investigate to help you out.

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.
Rendering

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.