我们可以通过 aspose slide java 将 Excel 文件作为链接嵌入到 ppt 中吗?目前我已经尝试使用 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.........");
}
}