This article demonstrates how to insert an Excel file as an OEL object into a PowerPoint document using Spire.Presentation for Java.
import com.spire.presentation.FileFormat; import com.spire.presentation.IOleObject; import com.spire.presentation.Presentation; import com.spire.presentation.SlideSizeType; import com.spire.presentation.drawing.IImageData; import javax.imageio.ImageIO; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileInputStream; public class EmbedExcel { public static void main(String[] args) throws Exception { //Create a Presentation object Presentation ppt = new Presentation(); ppt.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9); //Load an image file and add it to the image collection of the presentation File file = new File("C:\\Users\\Administrator\\Desktop\\image.png"); BufferedImage image = ImageIO.read(file); IImageData oleImage = ppt.getImages().append(image); //Load an Excel file and convert it to byte[] object String excelPath = "C:\\Users\\Administrator\\Desktop\\data.xlsx"; File excelFile = new File(excelPath); FileInputStream inputStream = new FileInputStream(excelFile); byte[] data = new byte[(int) excelFile.length()]; inputStream.read(data, 0, data.length); //Create a Rectangle2D object Rectangle2D rect = new Rectangle2D.Float(60, 60, image.getWidth(), image.getHeight()); //Insert the Excel file as an OLE object to the first slide IOleObject oleObject = ppt.getSlides().get(0).getShapes().appendOleObject("excel", data, rect); oleObject.getSubstituteImagePictureFillFormat().getPicture().setEmbedImage(oleImage); oleObject.setProgId("Excel.Sheet.12"); //Save to another file ppt.saveToFile("InsertOle.pptx", FileFormat.PPTX_2013); } }