OleObjectFrame.ObjectData --> Microsoft.Office.Interop.Graph.Chart

Dear Todd,

I have been informed by my team lead to use Worksheets.SetOleSize API to set the size of OLE excel chart. I found out, with the help of this API we can scale our modified Excel Chart up/down.

The code below is the exactly the same as your code only one line is added to it, which is highlighted. Hopefully, it would be helpful for you.

I have also attached the source and output presentation files.

void AddExcelChart()
{
    //Source presentation contains Excel Chart object,
    //Which was inserted inside the slide using Insert-->Object
    Presentation srcPres = new Presentation("srcExcelChart.ppt");
    Slide fstSlide = srcPres.GetSlideByPosition(1);

    //The alternative text of the source is set as oleobject
    //to get its reference quickly
    Shape srcShape = fstSlide.FindShape("oleobject");
    OleObjectFrame oof = (OleObjectFrame)srcShape;

    // check, if OleObjectFrame is not null then read the
    // object data of OleObjectFrame as an array of bytes.
    if (oof != null)
    {
        // create a workbook
        Workbook wb = new Workbook();

        // open the Excel Chart inside the workbook
        MemoryStream msIn = new MemoryStream(oof.ObjectData);
        wb.Open(msIn);

        //I have tried these parameters, you can try others
        //to scale up/down your chart
        wb.Worksheets.SetOleSize(1, 40, 1, 40);

        // set some data
        wb.Worksheets[1].Cells[1, 1].PutValue(0.6859);
        wb.Worksheets[1].Cells[2, 1].PutValue(0.5);
        wb.Worksheets[1].Cells[3, 1].PutValue(0.6346);
        wb.Worksheets[1].Cells[1, 2].PutValue(0.662327);
        wb.Worksheets[1].Cells[2, 2].PutValue(0.884594);
        wb.Worksheets[1].Cells[3, 2].PutValue(0.629499);
        wb.Worksheets[1].Cells[1, 3].PutValue(0.70415);
        wb.Worksheets[1].Cells[2, 3].PutValue(0.875956);
        wb.Worksheets[1].Cells[3, 3].PutValue(0.676291);

        // now save back the modified workbook to memory stream
        MemoryStream msOut = wb.SaveToStream();
        oof.ObjectData = msOut.ToArray();
    }

    //Write the presentation on disk
    srcPres.Write("outExcelChart.ppt");

    ////Now look at the second slide, doubl click it, then click chart tab at
    ////the bottom with three other tabs and see the modified chart
}

Take care and have a nice day.

Well, I have tried using the SetOleSize(), but it makes no difference. I've attached my sample project. Note the difference in size in the chart before/after:

1. Open in.ppt, right-click on the chart, select Size. Object is 2.12" x 4.16"

2. Open out.ppt, right-click on the chart, select Size. Object is 5.38" x 9.96"

One note, you will need to use your own Aspose.Total.lic file -- for obvious reasons I have removed it from the project directory. When you run this without a license file, the behavior is different.

Well, I have tried using the SetOleSize(), but it makes no difference. I've attached my sample project. Note the difference in size in the chart before/after:

1. Open in.ppt, right-click on the chart, select Size. Object is 2.12" x 4.16"

2. Open out.ppt, right-click on the chart, select Size. Object is 5.38" x 9.96"

One note, you will need to use your own Aspose.Total.lic file -- for obvious reasons I have removed it from the project directory. When you run this without a license file, the behavior is different.

Dear toddba,

Your input chart dimensions are 12 rows, 6 columns, so you should set it

wb.Worksheets.SetOleSize(1, 12, 1, 6);

I believe my worksheet is actually 4 x 4.

At any rate, your code – wb.Worksheets.SetOleSize(1, 12, 1, 6) – works fine, as long as the following line which loads the License file is commented out:

try
{
    // Set Aspose License
    Aspose.Slides.License slideLic = new Aspose.Slides.License();
    Aspose.Cells.License cellsLic = new Aspose.Cells.License();
    slideLic.SetLicense("C:\\Source\\BO.DocBuilder.Test\\Aspose.Total.lic");
    //cellsLic.SetLicense("C:\\Source\\BO.DocBuilder.Test\\Aspose.Total.lic");
}

When you load the license file, it does not add the 3rd worksheet (the one with the “This is an evaluation copy” message), and the scale of the object is completely off.

Todd

msfaiz:

Dear toddba,

Your input chart dimensions are 12 rows, 6 columns, so you should set it

wb.Worksheets.SetOleSize(1, 12, 1, 6);

Hello Todd,

Actually, the visible size of your work sheet is 12 rows and 6 columns. I will request a license for Aspose.Cells and check this problem.

Take care,

Dear Todd,

This is a quotation from our service team lead

“This customer is using Aspose.Total license. It’s one license file, Aspose.Total.lic that he is referencing in two components. Is his problem due to referencing same license file for two times in different methods? Please check it out.

If you still think that Aspose.Cells license is necessary to resolve this issue, please let me know and i will provide you.”

Please follow these instructions and then let me know, do they work or not?

Sorry, I have absolutely no idea what he is talking about, or what he wants me to do.

Yes, we only have 1 license file (Aspose.Total.lic). But in order to prevent the “evaluation copy” messages from showing up, I have to create two License objects – one for Slides, and one for Cells.

Am I doing this incorrectly??? And how is it possible that you are a Support Engineer for Aspose and you don’t even have a product license for the products you support?

Todd

msfaiz:

Dear Todd,

This is a quotation from our service team lead

“This customer is using Aspose.Total license. It’s one license file, Aspose.Total.lic that he is referencing in two components. Is his problem due to referencing same license file for two times in different methods? Please check it out.

If you still think that Aspose.Cells license is necessary to resolve this issue, please let me know and i will provide you.”

Please follow these instructions and then let me know, do they work or not?

In the licensed version, SetOleSize does not work. I have posted the request for the fix here http://www.aspose.com/Community/forums/72379/ShowThread.aspx#72379

Hello, I am new to Aspose.Slides and I was trying to convert from using MS Interop interface. Our Powerpoint template contains Excel objects that are referenced when the presentation is built and the data is updated at that time.

This thread seemed to address how to reference that Excel object but the code below does not work for me. My Excel Workbook object does not have an open method. Is this code referencing an ASPOSE.CELLS workbook? (I don't have aspose.cells)

//Create a workbook
Workbook wb = new Workbook();
//Open the Excel Chart inside the workbook
MemoryStream ms = new MemoryStream(msExcelObj.ObjectData);
wb.Open(ms);

ekelly:

Hello, I am new to Aspose.Slides and I was trying to convert from using MS Interop interface. Our Powerpoint template contains Excel objects that are referenced when the presentation is built and the data is updated at that time.

This thread seemed to address how to reference that Excel object but the code below does not work for me. My Excel Workbook object does not have an open method. Is this code referencing an ASPOSE.CELLS workbook? (I don't have aspose.cells)

//Create a workbook
Workbook wb = new Workbook();
//Open the Excel Chart inside the workbook
MemoryStream ms = new MemoryStream(msExcelObj.ObjectData);
wb.Open(ms);

That's correct. Our solution utlized both Aspose.Slides and Aspose.Cells to manipulate the embedded excel chart data.

Todd

Hello Eileen,

You should also see this thread for complete example of creating Excel Charts from scratch using Aspose.Cells and then embedding it inside PowerPoint slide using Aspose.Cells.

Creating Excel chart and embedding them as OLE Object inside a Presentation

So from your answer I take it that what I am asking for is not possible, I can not use Excel to manipulate the Excel object in an Aspose Slide?

Hello,

Once you embedded your excel chart in the PowerPoint slide with Aspose.Slides, you can manipulate with MS-Excel by double clicking it.

If you visit the thread I pasted earlier, you will find the output presentation with embedded excel object, double click it and you will see , it opens in MS-Excel which you can then manipulate and save changes.

I think you misread… I am trying to manipulate the Excel object in code, not after the presentation is complete. Without Aspose.Cells, just Aspose.Slides.

Hello,

Thanks for clarification.

No, Aspose.Slides will not help you to manipulate the chart data. You need to use some other component to do this job.

Yes, this code is referencing ASPOSE.CELLS Workbook.

Workbook wb = new Workbook();
MemoryStream msIn = new MemoryStream(oof.ObjectData);

wb.Open(msIn);
Aspose.Cells.Worksheet ws = wb.Worksheets[“Sheet1”];
Aspose.Cells.Cells cells = ws.Cells;

cells[“B2”].PutValue(32);
cells[“B3”].PutValue(38);
cells[“B4”].PutValue(15);

msOut = wb.SaveToStream();
oof.ObjectData = msOut.ToArray();