我们在编辑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)
效果展示: