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 中替换图像,如果您有其他问题也可以继续浏览本系列文章,获取相关教程,你还可以给我留言或者加入我们的官方技术交流群。 

相关内容

热门资讯

AWSECS:访问外部网络时出... 如果您在AWS ECS中部署了应用程序,并且该应用程序需要访问外部网络,但是无法正常访问,可能是因为...
AWSElasticBeans... 在Dockerfile中手动配置nginx反向代理。例如,在Dockerfile中添加以下代码:FR...
AWR报告解读 WORKLOAD REPOSITORY PDB report (PDB snapshots) AW...
AWS管理控制台菜单和权限 要在AWS管理控制台中创建菜单和权限,您可以使用AWS Identity and Access Ma...
北信源内网安全管理卸载 北信源内网安全管理是一款网络安全管理软件,主要用于保护内网安全。在日常使用过程中,卸载该软件是一种常...
​ToDesk 远程工具安装及... 目录 前言 ToDesk 优势 ToDesk 下载安装 ToDesk 功能展示 文件传输 设备链接 ...
Azure构建流程(Power... 这可能是由于配置错误导致的问题。请检查构建流程任务中的“发布构建制品”步骤,确保正确配置了“Arti...
群晖外网访问终极解决方法:IP... 写在前面的话 受够了群晖的quickconnet的小水管了,急需一个新的解决方法&#x...
AWSECS:哪种网络模式具有... 使用AWS ECS中的awsvpc网络模式来获得最佳性能。awsvpc网络模式允许ECS任务直接在V...
不能访问光猫的的管理页面 光猫是现代家庭宽带网络的重要组成部分,它可以提供高速稳定的网络连接。但是,有时候我们会遇到不能访问光...