简体   繁体   English

我们可以通过aspose slide java在ppt中嵌入Excel文件吗

[英]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.我们可以通过 aspose slide java 将 Excel 文件作为链接嵌入到 ppt 中吗? 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.目前我已经尝试使用 Aspose slide ,该对象嵌入在 pptx 文件中,但在尝试打开文件时出现异常。请给我一些功能指南。下面附上示例代码。

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.........");

    }

}

@Bachan Joseph, @Bachan约瑟夫,

I have observed the sample code shared by you and there seems to be no issue in sample code while adding MS Excel OLE object in PowerPoint presentation.我已经观察到您共享的示例代码,在 PowerPoint 演示文稿中添加 MS Excel OLE 对象时,示例代码似乎没有问题。 There may be issue with source files.源文件可能有问题。 Can you please share the source file with which you are getting exception along with stack trace so that we may observe that further to help you.您能否分享您收到异常的源文件以及堆栈跟踪,以便我们进一步观察以帮助您。

I am working as support developer in Aspose.我在 Aspose 担任支持开发人员。

The below code is working fine for me to attach the excel file to a PPT using Aspose slide下面的代码工作正常,我可以使用 Aspose 幻灯片将 excel 文件附加到 PPT

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM