C# 插入图片到Word表格
1、通过官网(https://www.e-iceblue.cn/Introduce/Free-Spire-Doc-NET.html)下载安装包--解压-安装。在程序中添加引用Spire.doc.dll,dll文件在安装路径下的bin文件夹中。
2.通过Nuget官网下载。(http://www.nuget.org/packages/FreeSpire.Doc/)
添加引用完成后,如下图:

1、using Spire.Doc;
using Spire.Doc.Fields;
using System.Drawing;
namespace InsertImgToTable_Doc
{
class Program
{
static void Main(string[] args)
{
//创建一个document实例并加载示例文档
Document doc = new Document();
doc.LoadFromFile("sample.docx");
//获取第一个table
Table table1 = (Table)doc.Sections[0].Tables[0];
//插入图片到表格并设置图片宽度和高度
DocPicture picture1 = table1.Rows[1].Cells[0].Paragraphs[0].AppendPicture(Image.FromFile("zg.png"));
picture1.Width = 110;
picture1.Height = 87;
DocPicture picture2 = table1.Rows[1].Cells[1].Paragraphs[0].AppendPicture(Image.FromFile("gq.png"));
picture2.Width = 110;
picture2.Height = 87;
DocPicture picture3 = table1.Rows[1].Cells[2].Paragraphs[0].AppendPicture(Image.FromFile("gh.png"));
picture3.Width = 110;
picture3.Height = 87;
//保存文档
doc.SaveToFile("result.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("result.docx");
}
}
}
2、图片插入效果前后对比:
