Create and Embed an Excel Chart as an OLE Object into a Microsoft PowerPoint Slide

Creating and Embedding an Excel Chart

The two code examples below are long and detailed because the task they’re describing is involved. You create a Microsoft Excel workbook, create a chart and then create the Microsoft PowerPoint presentation that you’ll embed the chart into. OLE objects contain links to the original document so a user that double-clicks the embedded file will launch the file and it’s application.

VSTO Example

Using VSTO, the following steps are performed:

  1. Create an instance of the Microsoft Excel ApplicationClass object.
  2. Create a new workbook with one sheet in it.
  3. Add chart to the sheet.
  4. Save the workbook.
  5. Open the Excel workbook containing the worksheet with the chart data.
  6. Get the ChartObjects collection for the sheet.
  7. Get the chart to copy.
  8. Create a Microsoft PowerPoint presentation.
  9. Add a blank slide to the presentation.
  10. Copy the chart from the Excel worksheet to the clipboard.
  11. Paste the chart into the PowerPoint presentation.
  12. Position the chart on the slide.
  13. Save the presentation.

Aspose.Slides for Java Example

Using Aspose.Slides for .NET, the following steps are performed:

  1. Create a workbook using Aspose.Cells for Java.
  2. Create a Microsoft Excel chart.
  3. Set the OLE size of the Excel Chart.
  4. Get an image of the chart.
  5. Embed the Excel chart as an OLE Object inside PPTX presentation using Aspose.Slides for Java.
  6. Replace the object changed image with the image obtained in step 3 to cater for the object changed issue.
  7. Write the output presentation to disk in PPTX format.