spire.presentation for .net 6.1版本支持嵌入zip对象到ppt幻灯片。下面通过c#及vb.net代码展示如何来实现zip对象添加。在ppt中嵌入excel对象可参考这篇文章。
c#
using spire.presentation;
using spire.presentation.drawing;
using system;
using system.drawing;
using system.io;
namespace insertzip
{
class program
{
static void main(string[] args)
{
//创建一个ppt文档,并获取第一张幻灯片(创建的ppt默认包含一张空白幻灯片)
presentation ppt = new presentation();
islide slide = ppt.slides[0];
//读取zip文件到byte数组
byte[] data = file.readallbytes("sample.zip");
//在幻灯片中绘制形状,并添加zip文件对象
rectangle rec = new rectangle(120, 120, 100, 100);
ioleobject ole = slide.shapes.appendoleobject("sample.zip", data, rec);
ole.progid = "package";
//设置对象封面图片
image image = image.fromfile("logo.png");
iimagedata oleimage = ppt.images.append(image);
ole.substituteimagepicturefillformat.picture.embedimage = oleimage;
//保存文档
ppt.savetofile("insertzip.pptx", spire.presentation.fileformat.pptx2013);
system.diagnostics.process.start("insertzip.pptx");
}
}
}
vb.net
imports spire.presentation
imports spire.presentation.drawing
imports system.drawing
imports system.io
namespace insertzip
class program
private shared sub main(args as string())
'创建一个ppt文档,并获取第一张幻灯片(创建的ppt默认包含一张空白幻灯片)
dim ppt as new presentation()
dim slide as islide = ppt.slides(0)
'读取zip文件到byte数组
dim data as byte() = file.readallbytes("sample.zip")
'在幻灯片中绘制形状,并添加zip文件对象
dim rec as new rectangle(120, 120, 100, 100)
dim ole as ioleobject = slide.shapes.appendoleobject("sample.zip", data, rec)
ole.progid = "package"
'设置对象封面图片
dim image__1 as image = image.fromfile("logo.png")
dim oleimage as iimagedata = ppt.images.append(image__1)
ole.substituteimagepicturefillformat.picture.embedimage = oleimage
'保存文档
ppt.savetofile("insertzip.pptx", spire.presentation.fileformat.pptx2013)
system.diagnostics.process.start("insertzip.pptx")
end sub
end class
end namespace
嵌入效果: