Word控件Spire.Doc 【图像形状】教程(8): 如何借助C#/VB.NET在 Word 中插入艺术字
创始人
2024-03-03 02:20:42
0

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

Spire.Doc for.NET 最新下载(qun:767755948)icon-default.png?t=M85Bhttps://www.evget.com/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(float width , float height , ShapeType shapeType )方法指定形状大小和类型。
  • 使用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 instance
Document doc = new Document();//Add a section
Section section = doc.AddSection();//Add a paragraph
Paragraph paragraph = section.AddParagraph();//Append a shape to the paragraph and specify the shape size and type
ShapeObject shape = paragraph.AppendShape(400, 150, ShapeType.TextDeflateBottom);//Set the position of the shape
shape.VerticalPosition = 60;
shape.HorizontalPosition = 60;//Set the text of WordArt
shape.WordArt.Text = "Create WordArt in Word";//Set the fill color and stroke color of WordArt
shape.FillColor = System.Drawing.Color.Cyan;
shape.StrokeColor = System.Drawing.Color.DarkBlue;//Save the document
doc.SaveToFile("CreateWordArt.docx", FileFormat.Docx2013);
}
}
}

【VB.NET】

Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.FieldsNamespace CreatWordArt
Class Program
Private Shared Sub Main(ByVal args As String())'Create a Document instance
Dim doc As Document = New Document()'Add a section
Dim section As Section = doc.AddSection()'Add a paragraph
Dim paragraph As Paragraph = section.AddParagraph()'Append a shape to the paragraph and specify the shape size and type
Dim shape As ShapeObject = paragraph.AppendShape(400, 150, ShapeType.TextDeflateBottom)'Set the position of the shape
shape.VerticalPosition = 60
shape.HorizontalPosition = 60'Set the text of WordArt
shape.WordArt.Text = "Create WordArt in Word"'Set the fill color and stroke color of WordArt
shape.FillColor = System.Drawing.Color.Cyan
shape.StrokeColor = System.Drawing.Color.DarkBlue'Save the document
doc.SaveToFile("CreateWordArt.docx", FileFormat.Docx2013)
End Sub
End Class
End Namespace

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

相关内容

热门资讯

前端-session、jwt 目录:   (1)session (2&#x...
linux入门---制作进度条 了解缓冲区 我们首先来看看下面的操作: 我们首先创建了一个文件并在这个文件里面添加了...
关于测试,我发现了哪些新大陆 关于测试 平常也只是听说过一些关于测试的术语,但并没有使用过测试工具。偶然看到编程老师...
前缀和与对数器与二分法 1. 前缀和 假设有一个数组,我们想大量频繁的去访问L到R这个区间的和,...
nodejs:本地安装nvm实... 一、背景-使用不同版本node的原因 vue3+ts、nuxt3版本,node...
JAVA集合知识整理 Java集合知识整理 HashMap相关 HashMap的底层数据结构:jdk1.8之...
无刷直流电机介绍及单片机控制实... 无刷直流电机介绍及单片机控制实例前言基本概念优势与劣势使用寿命基本结构使用单片机控制实例电子调速器&...
fwdiary(2) dp2 1.传纸条  AcWing 275. 传纸条 - AcWing 走两条路,走一条最大的...
常用的DOS命令 常用的DOS命令 DOS(Disk Operating System,磁...
<C++> 类和对象(下) 1.const成员函数将const修饰的“成员函数”称之为const成员函数,cons...