经过几天的研究,终于发现了向Word表格中单元格添加图片的方法,如下:
XWPFTableCell Cell = table.GetRow(3).GetCell(0);//获取到进行图片插入的单元格
//单元格的宽度和高度
var cW = 1000;var cH = 1000;
//得到要插入的图片
var img = new FileStream(图片路径, FileMode.Open, FileAccess.Read);
//进行图片插入
XWPFRun run= p.CreateRun();
var widthPic = (int)((double)cW / 587 * 38.4 * 9525);
var heightPic= (int)((double)cH / 587 * 38.4 * 9525);
run.AddPicture(img, (int)NPOI.XWPF.UserModel.PictureType.JPEG, "11.png", widthPic , heightPic);
+加个补充:
跨列合并单元格:
table0.GetRow(int pos).MergeCells(int startIndex, int endIndex);
本文介绍了一种在Word文档的表格中插入图片的方法,并提供了具体的代码实现。此外,还介绍了如何通过代码实现Word表格中单元格的跨列合并。
5759





