How do you add attachments from a generic filetype using Apose.Slides using java?

80 Views Asked by At

How do you add attachments from a generic filetype using Apose.Slides using java?

The manual PowerPoint operation I’m trying to do programmatically is:

Insert -> Object -> From file

Is this possible with Aspose.Slides insert an Excel file as a link using java?

1

There are 1 best solutions below

0
On

The below code is working fine for attaching the Excel file using aspose slides

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();
        }
    }
}