本文我们将介绍如何使用spire.presentation for java将excel工作表作为ole对象插入到幻灯片。
import com.spire.presentation.*;
import com.spire.presentation.drawing.iimagedata;
import javax.imageio.imageio;
import java.awt.*;
import java.awt.image.bufferedimage;
import java.io.*;
public class embedexcelasole {
public static void main(string[] args) throws exception{
//新建powerpoint文档
presentation ppt = new presentation();
//插入图片到powerpoint文档
file file =new file("excel.png");
bufferedimage image = imageio.read(file);
iimagedata oleimage = ppt.getimages().append(image);
rectangle rec = new rectangle(80, 60, image.getwidth(), image.getheight());
//加载excel文档
string input = "sample.xlsx";
file oldfile=new file(input);
//将excel数据保存到流
fileinputstream inputstream = new fileinputstream(oldfile);
byte[] data = new byte[(int)oldfile.length()];
inputstream.read(data,0,data.length);
//根据excel数据将ole对象插入到powerpoint文档
com.spire.presentation.ioleobject oleobject=ppt.getslides().get(0).getshapes().appendoleobject("excel", data, rec);
oleobject.getsubstituteimagepicturefillformat().getpicture().setembedimage(oleimage);
oleobject.setprogid("excel.sheet.12");
//保存文档
ppt.savetofile("output/embedexcelasole.pptx", fileformat.pptx_2013);
inputstream.close();
}
}
效果图: