'Can we embed Excel file in ppt through aspose slide java

Can we embed Excel file as a link in ppt through aspose slide java. Currently I have tried with Aspose slide , the object was embedded in the pptx file but while trying to open the file getting exception.please give me some guidelines to functionality.The sample code attached below.

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;

import com.aspose.slides.AutoShape;
import com.aspose.slides.IOleObjectFrame;
import com.aspose.slides.ISlide;
import com.aspose.slides.License;
import com.aspose.slides.Presentation;
import com.aspose.slides.SaveFormat;
import com.aspose.slides.ShapeType;

public class PPTTest1 {

public  void setAsposeLicense() {
    InputStream inputStream = null;
    try {
        License license = new License();
        inputStream = getClass().getClassLoader().getResourceAsStream("C:\\work\\licence\\aspose.slides.lic");
        license.setLicense(inputStream);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (inputStream != null)
                inputStream.close();
        } catch (Exception e) {
            inputStream = null;
        }
    }
}
public static void main(String[] args) throws IOException {
        PPTTest1 ppt=new PPTTest1();
        ppt.setAsposeLicense();
        //Instantiate Prseetation class that represents the PPTX
        Presentation pres = new Presentation();
        //Access the first slide
        ISlide sld = pres.getSlides().get_Item(0);
        //Load an Excel file to Array of Bytes
        File file=new File("C:\\work\\Demo_uploadt.xlsm");
        int length=(int)file.length();
        FileInputStream fstro = new FileInputStream(file);
        byte[] buf = new byte[length];
        fstro.read(buf, 0, length);
        //Add an Ole Object Frame shape\

        byte[] fileContent = Files.readAllBytes(file.toPath());
        IOleObjectFrame ooff = sld.getShapes().insertOleObjectFrame(0,(float)0,(float) 0,100,400, "Excel.Sheet.10", fileContent);
        ooff.setObjectData(fileContent);
        pres.save("C:\\work\\OleEmbed.pptx", SaveFormat.Pptx);
        System.out.println("ppt generated.........");

    }

}


Solution 1:[1]

The below code is working fine for me to attach the excel file to a PPT using Aspose slide

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

import com.aspose.slides.IOleEmbeddedDataInfo;
import com.aspose.slides.IOleObjectFrame;
import com.aspose.slides.OleEmbeddedDataInfo;
import com.aspose.slides.Presentation;
import com.aspose.slides.SaveFormat;

public class SetFileTypeForAnEmbeddingObject2 {

    public static void main(String[] args) throws IOException {

        Presentation pres = new Presentation();
        try {
            // Add known Ole objects
            byte[] fileBytes = Files.readAllBytes(Paths.get("C:\\work\\Demo uploadt.xlsm"));

            // Create Ole embedded file info
            IOleEmbeddedDataInfo dataInfo = new OleEmbeddedDataInfo(fileBytes, "xls");

            // Create OLE object
            IOleObjectFrame oleFrame = pres.getSlides().get_Item(0).getShapes().addOleObjectFrame(150, 420, 250, 50,
                    dataInfo);
            oleFrame.setObjectIcon(true);

            pres.save("C:\\work\\" + "SetFileTypeForAnEmbeddingObject7.pptx", SaveFormat.Pptx);
        } finally {
            if (pres != null)
                pres.dispose();
        }
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bachan Joseph