Word控件Spire.Doc 【图像形状】教程(3) :在 C#/VB.NET 中的指定位置插入图像

图像可以为您的 Word 文档增添趣味并生效。假设你写了一篇介绍一个城市的文章,介绍它美丽的风景。仅仅用文字描述,你无法为你的读者呈现完美的风景,因为那一页的文字看起来模糊而沉闷。你需要图像来点缀你的风景。

Spire.Doc for .NET是一个专业的.NET word 组件,无需使用 MS Office 自动化即可快速生成、打开、修改和保存 Word 文档,使用户可以使用 C#.NET 将图像插入 Word 文档并根据页面设置其大小. 本指南介绍了如何通过Spire.Doc for .NET插入图像的简单方法。

首先,新建 Word 文档并为该文档添加节、段。然后,在新创建的段落中插入图像。您可以设置此图像的大小、位置、旋转它并选择文本的环绕样式。下载并安装 Spire.Doc for .NET。使用以下代码通过 C# 在 Word 中插入图像。

示例演示展示了如何将图像插入到文档中。

在 Word 文档中插入图像
using System;using Spire.Doc;using Spire.Doc.Documents;using Spire.Doc.Fields;using System.Drawing;namespace Insert_image_to_Word_Document{class Program{static void Main(string[] args){//Open a blank word document as templateDocument document = new Document(@"Blank.doc");Section section = document.Sections[0];Paragraph paragraph= section.Paragraphs.Count > 0 section.Paragraphs[0] : section.AddParagraph();paragraph.AppendText("The sample demonstrates how to insert an image into a document.");paragraph.ApplyStyle(BuiltinStyle.Heading2);paragraph = section.AddParagraph();//get original imageBitmap p = new Bitmap(Image.FromFile(@"Word.jpg"));//rotate image and insert image to word documentp.RotateFlip(RotateFlipType.Rotate90FlipX);DocPicture picture = document.Sections[0].Paragraphs[0].AppendPicture(p);//set image's positionpicture.HorizontalPosition = 50.0F;picture.VerticalPosition = 60.0F;//set image's sizepicture.Width = 200;picture.Height = 200;//set textWrappingStyle with image;picture.TextWrappingStyle = TextWrappingStyle.Through;//Save doc file.document.SaveToFile("Sample.doc", FileFormat.Doc);//Launching the MS Word file. System.Diagnostics.Process.Start("Sample.doc");}}}

如果您已完成教程Spire.Doc 快速入门,上述步骤会更简单。

使用Spire.Doc,您可以将图像插入 Word 文档,并在 ASP.NET、WPF 和 Silverlight 应用程序中执行更多相同操作,而无需 Word 自动化和任何其他第三方插件。

以上便是如何在 C#/VB.NET 中的指定位置插入图像,如果您有其他问题也可以继续浏览本系列文章,获取相关教程,你还可以给我留言或者加入我们的官方技术交流群。


欢迎下载|体验更多E-iceblue产品

获取更多信息请咨询在线客服  


标签:

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

上一篇 2022年8月24日
下一篇 2022年8月24日

相关推荐

发表回复

登录后才能评论