更多资源查看:Spire.Doc文本教程 | Spire.XLS图表系列教程 | Spire.PDF系列教程
【下载Spire.Doc最新试用版】
在指定位置插入图片
//实例化一个Document对象Document doc = new Document();//添加section和段落Section section = doc.AddSection();Paragraph para = section.AddParagraph();//加载图片到System.Drawing.Image对象, 使用AppendPicture方法将图片插入到段落Image image = Image.FromFile(@"C:UsersAdministratorDesktoplogo.png");DocPicture picture = doc.Sections[0].Paragraphs[0].AppendPicture(image);//设置文字环绕方式picture.TextWrappingStyle = TextWrappingStyle.Square;//指定图片位置picture.HorizontalPosition = 50.0f;picture.VerticalPosition = 50.0f;//设置图片大小picture.Width = 100;picture.Height = 100;//保存到文档doc.SaveToFile("Image.doc", FileFormat.Doc);
效果图:

提取Word文档中的图片
//初始化一个Document实例并加载Word文档Document doc = new Document();doc.LoadFromFile(@"Image.doc");int index = 0;//遍历Word文档中每一个sectionforeach (Section section in doc.Sections){ //遍历section中的每个段落 foreach (Paragraph paragraph in section.Paragraphs) { //遍历段落中的每个DocumentObject foreach (DocumentObject docObject in paragraph.ChildObjects) { //判断DocumentObject是否为图片 if (docObject.DocumentObjectType == DocumentObjectType.Picture) { //保存图片到指定路径并设置图片格式 DocPicture picture = docObject as DocPicture; String imageName = String.Format(@"imagesImage-{0}.png", index); picture.Image.Save(imageName, System.Drawing.Imaging.ImageFormat.Png); index++; } } }}
效果图:

如果你有任何问题或意见,请在下方评论区留言~
想要购买正版授权,或者获取更多Spire.XLS相关信息的朋友可以点击” 咨询在线客服“~

标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!