900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > NPOI Word插入图片的方法

NPOI Word插入图片的方法

时间:2018-10-31 21:55:24

相关推荐

NPOI Word插入图片的方法

从资源文件中加载图片插入到word中:

Assembly assm = Assembly.GetExecutingAssembly();Stream istr = assm.GetManifestResourceStream("idgt_converter.Resources.caution.png");XWPFParagraph p = table.GetRow(rowIndex).GetCell(i).AddParagraph();XWPFRun r = p.CreateRun();var widthPx = Resource.caution.Width;var heightPx = Resource.caution.Height;var horzRezDpi = Resource.caution.HorizontalResolution;var vertRezDpi = Resource.caution.VerticalResolution;const int emusPerInch = 914400;var widthEmus = (int)(widthPx / horzRezDpi * emusPerInch);var heightEmus = (int)(heightPx / vertRezDpi * emusPerInch);XWPFPicture pic = r.AddPicture(istr, (int)PictureType.PNG, "caution.png", widthEmus, heightEmus);

AddPicture方法的宽和高要注意,不是图片的像素,而是需要根据像素和分辨率计算出来的值。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。