C# 如何在Word文档中插入艺术字

来源:互联网 发布:搜狗高速浏览器mac版 编辑:程序博客网 时间:2024/05/21 15:05

C# 如何在Word文档中插入艺术字

在Word文档中添加艺术字效果可以让文档的排版更加美观。本篇文章主要介绍如何使用C#和Spire.Doc组件在Word文档中插入艺术字。


Spire.Doc支持多种形状类型,其中包括艺术字,这些类型可以在ShapeType枚举中找到。下面的示例添加了其中两种艺术字到Word文档。

详细步骤:

步骤1:新建一个Word文档。

Document doc = new Document();

步骤2:添加一个节和一个段落到文档。

Section section = doc.AddSection();Paragraph paragraph = section.AddParagraph();

步骤3:插入形状到段落并指定形状的类型为艺术字。设置艺术字的文本,位置,填充色和描边色。

ShapeObject shape =paragraph.AppendShape(120, 30, ShapeType.TextWave);shape.WordArt.Text = "感谢阅读";shape.VerticalPosition = 80;shape.HorizontalPosition = 170;           shape.FillColor = Color.Yellow;shape.StrokeColor = Color.SeaGreen; shape = paragraph.AppendShape(120, 30, ShapeType.TextSlantUp);shape.WordArt.Text = "欢迎回来";shape.VerticalPosition = 150;shape.HorizontalPosition = 170;shape.FillColor = Color.Yellow;shape.StrokeColor = Color.Red;

步骤4:保存文档。

doc.SaveToFile("艺术字.docx",FileFormat.Docx2013);

效果图:

 


完整代码:

using System.Drawing;using Spire.Doc;using Spire.Doc.Documents;using Spire.Doc.Fields; namespace WordArt{    class Program    {        static void Main(string[] args)        {            //新建Word文档            Document doc = newDocument();             //添加节和段落            Section section = doc.AddSection();            Paragraph paragraph = section.AddParagraph();            //插入形状到段落并指定形状的类型为艺术字。设置艺术字的文本,位置,填充色和描边色           ShapeObject shape =paragraph.AppendShape(120, 30, ShapeType.TextWave);           shape.WordArt.Text = "感谢阅读";           shape.VerticalPosition = 80;           shape.HorizontalPosition = 170;                      shape.FillColor = Color.Yellow;           shape.StrokeColor = Color.SeaGreen;             shape = paragraph.AppendShape(120, 30, ShapeType.TextSlantUp);           shape.WordArt.Text = "欢迎回来";           shape.VerticalPosition = 150;           shape.HorizontalPosition = 170;           shape.FillColor = Color.Yellow;           shape.StrokeColor = Color.Red;             //保存文档           doc.SaveToFile("艺术字.docx", FileFormat.Docx2013);        }    }}


原创粉丝点击