Create and Embed an Excel Chart as an OLE Object into a Microsoft PowerPoint Slide
Contents
[
Hide
]
Charts are visual representations of your data and widely used in presentation slides. This article will show you the code to create and embed an Excel Chart as an OLE Object in the PowerPoint Slide programmatically by using VSTO and Aspose.Slides for Java.
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:
- Create an instance of the Microsoft Excel ApplicationClass object.
- Create a new workbook with one sheet in it.
- Add chart to the sheet.
- Save the workbook.
- Open the Excel workbook containing the worksheet with the chart data.
- Get the ChartObjects collection for the sheet.
- Get the chart to copy.
- Create a Microsoft PowerPoint presentation.
- Add a blank slide to the presentation.
- Copy the chart from the Excel worksheet to the clipboard.
- Paste the chart into the PowerPoint presentation.
- Position the chart on the slide.
- Save the presentation.
Aspose.Slides for Java Example
Using Aspose.Slides for .NET, the following steps are performed:
- Create a workbook using Aspose.Cells for Java.
- Create a Microsoft Excel chart.
- Set the OLE size of the Excel Chart.
- Get an image of the chart.
- Embed the Excel chart as an OLE Object inside PPTX presentation using Aspose.Slides for Java.
- Replace the object changed image with the image obtained in step 3 to cater for the object changed issue.
- Write the output presentation to disk in PPTX format.