我们在编辑ppt文档时,有时需要在表格中添加图片以使得内容更加丰富。下面将详细介绍如何使用spire.presnetation在表格单元格中添加图片。
c#
//创建一个ppt对象
presentation presentation = new presentation();
//创建一个表格并设置其样式
islide slide = presentation.slides[0];
double[] widths = new double[] { 120, 120 };
double[] heights = new double[] { 120, 120 };
itable table = presentation.slides[0].shapes.appendtable(100, 80, widths, heights);
table.stylepreset = tablestylepreset. mediumstyle4accent1;
//嵌入图片到表格的第一个单元格
iimagedata imgdata = presentation.images.append(image.fromfile("1.jpg"));
table[0, 0].fillformat.filltype = fillformattype.picture;
table[0, 0].fillformat.picturefill.picture.embedimage = imgdata;
table[0, 0].fillformat.picturefill.filltype = picturefilltype.stretch;
//保存文档
presentation.savetofile("table.pptx", fileformat.pptx2010);
vb.net
'创建一个ppt对象
dim presentation as new presentation()
'创建一个表格并设置其样式
dim slide as islide = presentation.slides(0)
dim widths as [double]() = new double() {120, 120}
dim heights as [double]() = new double() {120, 120}
dim table as itable = presentation.slides(0).shapes.appendtable(100, 80, widths, heights)
table.stylepreset = tablestylepreset.mediumstyle4accent1
'嵌入图片到表格的第一个单元格
dim imgdata as iimagedata = presentation.images.append(image.fromfile("1.jpg"))
table(0, 0).fillformat.filltype = fillformattype.picture
table(0, 0).fillformat.picturefill.picture.embedimage = imgdata
table(0, 0).fillformat.picturefill.filltype = picturefilltype.stretch
'保存文档
presentation.savetofile("table.pptx", fileformat.pptx2010)
效果展示: