700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > Word控件Spire.Doc 【图像形状】教程(8): 如何借助C#/VB.NET在 Word 中插入艺术字

Word控件Spire.Doc 【图像形状】教程(8): 如何借助C#/VB.NET在 Word 中插入艺术字

时间:2023-09-04 15:14:37

相关推荐

Word控件Spire.Doc 【图像形状】教程(8): 如何借助C#/VB.NET在 Word 中插入艺术字

Spire.Doc for .NET是一款专门对 Word 文档进行操作的 .NET 类库。在于帮助开发人员无需安装 Microsoft Word情况下,轻松快捷高效地创建、编辑、转换和打印 Microsoft Word 文档。拥有近专业开发经验Spire系列办公文档开发工具,专注于创建、编辑、转换和打印Word/PDF/Excel等格式文件处理,小巧便捷。在 C#、 中从 Word 中提取图像。

Spire.Doc 最新下载(qun:767755948)/product/3368/download

艺术字是 MS Word 中的一项功能,可让您在文档中插入色彩丰富且时尚的文本。除此之外,它还可以弯曲、拉伸或倾斜文本的形状,这是一种通过特殊效果使文本脱颖而出的快速方法。在本文中,您将学习如何使用Spire.Doc for .NET以编程方式将艺术字插入 Word 文档。

为 .NET 安装 Spire.Doc

首先,您需要添加 Spire.Doc for .NET 包中包含的 DLL 文件作为 .NET 项目中的引用。DLL 文件可以从此链接下载或通过NuGet安装。

PM> Install-Package Spire.Doc

在 Word 中插入艺术字

Spire.Doc 为 .NET 提供的ShapeType枚举定义了各种名称以“Text”开头的艺术字形状类型。为了在 Word 中创建艺术字,您需要初始化一个ShapeObject实例并指定艺术字类型和文本内容。详细步骤如下:

创建一个文档实例。使用Document.AddSection()方法向文档添加一个部分,然后使用Section.AddParagraph()方法向该部分添加一个段落。将形状附加到段落并使用Paragraph.AppendShape(floatwidth,floatheight,ShapeTypeshapeType)方法指定形状大小和类型。使用ShapeObject.VerticalPosition和ShapeObject.HorizontalPosition属性设置形状的位置。使用WordArt.Text属性设置艺术字的文本。使用ShapeObject.FillColor和ShapeObject.StrokeColor属性设置艺术字的填充颜色和描边颜色。使用Document.SaveToFile()方法将文档保存到另一个文件。

【C#】

using Spire.Doc;using Spire.Doc.Documents;using Spire.Doc.Fields;namespace CreatWordArt{class Program{static void Main(string[] args){//Create a Document instanceDocument doc = new Document();//Add a sectionSection section = doc.AddSection();//Add a paragraphParagraph paragraph = section.AddParagraph();//Append a shape to the paragraph and specify the shape size and typeShapeObject shape = paragraph.AppendShape(400, 150, ShapeType.TextDeflateBottom);//Set the position of the shapeshape.VerticalPosition = 60;shape.HorizontalPosition = 60;//Set the text of WordArtshape.WordArt.Text = "Create WordArt in Word";//Set the fill color and stroke color of WordArtshape.FillColor = System.Drawing.Color.Cyan;shape.StrokeColor = System.Drawing.Color.DarkBlue;//Save the documentdoc.SaveToFile("CreateWordArt.docx", FileFormat.Docx);}}}

【】

Imports Spire.DocImports Spire.Doc.DocumentsImports Spire.Doc.FieldsNamespace CreatWordArtClass ProgramPrivate Shared Sub Main(ByVal args As String())'Create a Document instanceDim doc As Document = New Document()'Add a sectionDim section As Section = doc.AddSection()'Add a paragraphDim paragraph As Paragraph = section.AddParagraph()'Append a shape to the paragraph and specify the shape size and typeDim shape As ShapeObject = paragraph.AppendShape(400, 150, ShapeType.TextDeflateBottom)'Set the position of the shapeshape.VerticalPosition = 60shape.HorizontalPosition = 60'Set the text of WordArtshape.WordArt.Text = "Create WordArt in Word"'Set the fill color and stroke color of WordArtshape.FillColor = System.Drawing.Color.Cyanshape.StrokeColor = System.Drawing.Color.DarkBlue'Save the documentdoc.SaveToFile("CreateWordArt.docx", FileFormat.Docx)End SubEnd ClassEnd Namespace

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

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